QTableWidget not Displaying multiple rows from SQL Query
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 :) )
Re: QTableWidget not Displaying multiple rows from SQL Query
Are you sure the loop runs more than one iteration?
Cheers,
_
Re: QTableWidget not Displaying multiple rows from SQL Query
Quote:
Originally Posted by
anda_skoa
Are you sure the loop runs more than one iteration?
Cheers,
_
It should, the database is correct (I tested it with the sql editor).
Re: QTableWidget not Displaying multiple rows from SQL Query
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,
_
Re: QTableWidget not Displaying multiple rows from SQL Query
Quote:
Originally Posted by
anda_skoa
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 ?
Re: QTableWidget not Displaying multiple rows from SQL Query
Quote:
Originally Posted by
cxam
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,
_
Re: QTableWidget not Displaying multiple rows from SQL Query
Quote:
Originally Posted by
anda_skoa
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
Re: QTableWidget not Displaying multiple rows from SQL Query
Quote:
Originally Posted by
cxam
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,
_
Re: QTableWidget not Displaying multiple rows from SQL Query
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.
Re: QTableWidget not Displaying multiple rows from SQL Query
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,
_
Re: QTableWidget not Displaying multiple rows from SQL Query
Indeed it ran 1 iteration and then stopped. Without creating a new row and without printing the new information from the query
Re: QTableWidget not Displaying multiple rows from SQL Query
Ok, so there is one row in your table as expected or is that row empty?
Cheers,
_
Re: QTableWidget not Displaying multiple rows from SQL Query
Can you simply attach the real CPP file to the post?
Re: QTableWidget not Displaying multiple rows from SQL Query
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 :)