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:
|
Source 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
|
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.