Results 1 to 10 of 10

Thread: Sql query to retrieve database table data

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #6
    Join Date
    Feb 2013
    Posts
    71
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    7

    Default Re: Sql query to retrieve database table data

    Quote Originally Posted by Lesiok View Post
    In line 11 You define pointer ui. Next You use this pointer in line 13 and 14 but the pointer is NOT initialised.
    I suggest first learn the basics of C++.
    I saw this later on and have changed my code quite a bit since that post. At the moment, only 1 label and lineEdit is showing up with 1 record, how do I make it one for each record? And my question on how to loop through all the total number of names from the sql query?

    My code now:
    Qt Code:
    1.  
    2. if (qry.exec("SELECT name FROM customer"))
    3. {
    4. while(qry.next())
    5. {
    6. qDebug() << qry.value(0).toString();
    7. if(qry.isValid())
    8. {
    9. QString cust = qry.record().value(0).toString();
    10. QLabel *label = new QLabel(QString(cust));
    11. QLineEdit *lineEdit = new QLineEdit;
    12. lineEdit->setInputMask("0");
    13. lineEdit->setMaxLength(1);
    14. lineEdit->setGeometry(0,0,41,31);
    15. label->setGeometry(0,0,150,41);
    16.  
    17. ui->gridLayout->addWidget(label,0,0); //<<<<<<<<<<<Fills the entire width of layout,why?
    18. ui->gridLayout->addWidget(lineEdit,0,1);//<<<<<<<<<<<Fills the entire width of layout,why?
    19. }
    20. }
    21. }
    22. else
    23. {
    24. qDebug() << qry.lastError();
    25. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by Cyrebo; 30th March 2013 at 09:35.

Similar Threads

  1. Replies: 3
    Last Post: 3rd October 2011, 09:08
  2. Replies: 1
    Last Post: 28th March 2010, 06:52
  3. SQL slow query - table update
    By lasher in forum Newbie
    Replies: 4
    Last Post: 22nd October 2009, 00:12
  4. Replies: 2
    Last Post: 14th September 2009, 09:38
  5. Replies: 2
    Last Post: 14th September 2009, 09:31

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
  •  
Qt is a trademark of The Qt Company.