PDA

View Full Version : QTableWidget not Displaying multiple rows from SQL Query



cxam
10th April 2016, 09:38
Hi, I'm having a little problem when displaying the select results from a SQL query into a QTableWidget, it only displays 1 row even though the "rowCount" is "row" which is a variable which increments +1 in a loop while "query.next()".

Here's my code:
http://paste.ofcode.org/HiuBnDNkrT9GhVR3qm7k29

Thanks in advance :)

(Btw it's my first post :) )

anda_skoa
10th April 2016, 10:41
Are you sure the loop runs more than one iteration?

Cheers,
_

cxam
10th April 2016, 13:07
Are you sure the loop runs more than one iteration?

Cheers,
_


It should, the database is correct (I tested it with the sql editor).

anda_skoa
10th April 2016, 16:47
So you have not checked if it actually runs multiple iterations?
E.g. by having a log output inside the loop or logging the value of "i" or "row" after the loop?

Cheers,
_

cxam
10th April 2016, 21:00
So you have not checked if it actually runs multiple iterations?
E.g. by having a log output inside the loop or logging the value of "i" or "row" after the loop?

Cheers,
_

Yes, everything works just perfectly, the variables return 1 in case of "i" and "2" in case of "row" unfortunately it doesn't creates another row, it's just one. Maybe I should set "
ui->tableWidget->setRowCount(row);" inside the loop ?

anda_skoa
10th April 2016, 22:57
Yes, everything works just perfectly, the variables return 1 in case of "i" and "2" in case of "row" unfortunately it doesn't creates another row, it's just one. Maybe I should set "
ui->tableWidget->setRowCount(row);" inside the loop ?

Maybe I misunderstood.

So your query has 1 result record, which is displayed in the table widget.
But you want the table widget to show two rows? One with the data from the query and an empty one?

Cheers,
_

cxam
11th April 2016, 07:23
Maybe I misunderstood.

So your query has 1 result record, which is displayed in the table widget.
But you want the table widget to show two rows? One with the data from the query and an empty one?

Cheers,
_


No, no the query actually has 3 records but it's only displaying 1

anda_skoa
11th April 2016, 09:50
No, no the query actually has 3 records but it's only displaying 1
Now I am even more confused.
You wrote that "i" has the value 1 after the loop, now you are saying it is 3?

Cheers,
_

cxam
12th April 2016, 15:47
Ok so let's make things a bit more clear hahaha
Well:

i = the number of the row where each piece of the query is printed
row = the total number of the quantity of rows

Those two both increment +1 each time the loop works starting with the values "i = 0" (The information is printed on the row nº 0) and "row = 1" (The table has a total of 1 row)

And then we have the number of results the query has (1 result per row) so it should print 3 total rows (SELECTED from the database) but unfortunately it only prints 1.

anda_skoa
12th April 2016, 23:33
I understood how the code works, I asked if you have confirmed that those two variables have the expected values after the loop.

You write that "i" has the value 1, which, if taken after the loop, would mean the loop ran one iteration.

Cheers,
_

cxam
14th April 2016, 22:36
Indeed it ran 1 iteration and then stopped. Without creating a new row and without printing the new information from the query

anda_skoa
15th April 2016, 10:20
Ok, so there is one row in your table as expected or is that row empty?

Cheers,
_

Lesiok
15th April 2016, 10:26
Can you simply attach the real CPP file to the post?

cxam
15th April 2016, 23:10
Ok guys I just figured it out, what I did to solve it was add a "ui->tableWidget->setRowCount(row);" at the end of the loop and actually it worked just fine. Thank you both for your help and time :)