Results 1 to 14 of 14

Thread: QTableWidget not Displaying multiple rows from SQL Query

  1. #1
    Join Date
    Apr 2016
    Posts
    7
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default 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 )

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,420
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QTableWidget not Displaying multiple rows from SQL Query

    Are you sure the loop runs more than one iteration?

    Cheers,
    _

  3. #3
    Join Date
    Apr 2016
    Posts
    7
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: QTableWidget not Displaying multiple rows from SQL Query

    Quote Originally Posted by anda_skoa View Post
    Are you sure the loop runs more than one iteration?

    Cheers,
    _

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

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,420
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default 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,
    _

  5. #5
    Join Date
    Apr 2016
    Posts
    7
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: QTableWidget not Displaying multiple rows from SQL Query

    Quote Originally Posted by anda_skoa View Post
    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 ?

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,420
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QTableWidget not Displaying multiple rows from SQL Query

    Quote Originally Posted by cxam View Post
    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,
    _

  7. #7
    Join Date
    Apr 2016
    Posts
    7
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: QTableWidget not Displaying multiple rows from SQL Query

    Quote Originally Posted by anda_skoa View Post
    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

  8. #8
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,420
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QTableWidget not Displaying multiple rows from SQL Query

    Quote Originally Posted by cxam View Post
    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,
    _

  9. #9
    Join Date
    Apr 2016
    Posts
    7
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default 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.

  10. #10
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,420
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default 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,
    _

  11. #11
    Join Date
    Apr 2016
    Posts
    7
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default 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

  12. #12
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,420
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default 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,
    _

  13. #13
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,460
    Thanked 271 Times in 266 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTableWidget not Displaying multiple rows from SQL Query

    Can you simply attach the real CPP file to the post?

  14. #14
    Join Date
    Apr 2016
    Posts
    7
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default 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

Similar Threads

  1. Replies: 5
    Last Post: 24th January 2014, 01:22
  2. QSQLITE: multiple instructions in SQL query
    By mcosta in forum Qt Programming
    Replies: 7
    Last Post: 9th March 2011, 22:27
  3. Replies: 4
    Last Post: 6th March 2011, 09:54
  4. QTableWidget - Select multiple rows.
    By wally in forum Qt Programming
    Replies: 2
    Last Post: 21st October 2008, 17:15
  5. QTableWidget Sql Query 25.000 records
    By aekilic in forum Qt Programming
    Replies: 2
    Last Post: 12th August 2008, 14:54

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.