Qt Forum - programming with C++ and Qt
Register Calendar Members List Team Members Search Frequently Asked Questions Go to the Main Page

Qt Forum - programming with C++ and Qt » QtForum.org » Qt » Qt Programming » Multithreading » Hello Guest [Login|Register]
Last Post | First Unread Post Print Page | Recommend to a Friend | Add Thread to Favorites
Post New Thread Post Reply
Go to the bottom of this page Multithreading
Author
Post « Previous Thread | Next Thread »
Donotalo Donotalo is a male
Software Engineer


images/avatars/avatar-420.jpg

Registration Date: 06.01.2008
Posts: 36
Location: Bangladesh

Level: 14 [?]
Experience: 4,730
Next Level: 5,517

787 points of experience needed for next level

Multithreading Reply to this Post Post Reply with Quote Edit/Delete Posts Report Post to a Moderator       Go to the top of this page

I've some computational tasks to do. Like generating 1 million vector<short> by computation and displaying them in a QTableWidget. I want that whenever a vector<short> is generated, it will be added at the last of QTableWidget and shown immediately. So that the so-far progress is always known. What is the proper way to do that?

Here is what I tried.

I've subclassed QThread for the computation and passed QTableWidget* to it for displaying purpose. Here is the subclass' cpp file:
code:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
void CodewordThread::initialize(int order, int vc, int vs, const short* _R, QTableWidget* tW) {
	vector_size = vs;
	tableWidget = tW;
	cgen.initialize(order, vc, vector_size, _R);
}

void CodewordThread::run() {
	long long i, j, k;
	pair< set< vector<short> >::iterator, bool> pr;
	QString str;
	QTableWidgetItem *item;

	k = cgen.getCount();
	tableWidget->setRowCount(k);
	for (i = 0; i < k; i++) {
		pr = codewords.insert(cgen.getData());
		if (pr.second) {
			str = "";
			for (j = 0; j < vector_size; j++)
				str += QString("%1").arg((*(pr.first))[j]);
			item = new QTableWidgetItem(str);
			tableWidget->setItem(i, 0, item);
		}
	}
}

The QTableWidget* is initialized in a QDialog subclass. I tested run()'s functionality there and the QTableWidget was properly shown with all the values. But nothing is shown if I use it here.

__________________
~Donotalo()
08.05.2008 16:00 Donotalo is offline Send an Email to Donotalo Search for Posts by Donotalo Add Donotalo to your Buddy List
Tree Structure | Board Structure
Jump to:
Post New Thread Post Reply
Qt Forum - programming with C++ and Qt » QtForum.org » Qt » Qt Programming » Multithreading

views today: 10.092 | views yesterday: 17.520 | total views: 10.243.461


Klebekork Shop - Linux Shop - Kontaktanzeigen - Linux Forum -  SMS Gewinnspiel -  Hotels -  Stadtpläne -  Branchenbuch & Stadtplan

Branchenbuch Österreich - Branchenbuch Niederlande - Portugal Branchenverzeichnis - Spanien Branchenverzeichnis 
Telefonbuch - Branchenbuch Frankreich