Results 1 to 5 of 5

Thread: from sqlquery to qstringlist

  1. #1
    Join Date
    Oct 2011
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default from sqlquery to qstringlist

    try to read a sqlquery, save it into a qstringlist and set it to combobox.
    pass compile but combobox is empty.
    Qt Code:
    1. QStringList cblist;
    2. QSqlQuery query;
    3. query.prepare("SELECT lastname FROM employeestuf");
    4. query.exec();
    5. while(query.next())
    6. {
    7. if (query.isValid())
    8. cblist<<query.value(0).toString();
    9. }
    10.  
    11. ui->comboBox->addItems(cblist);
    To copy to clipboard, switch view to plain text mode 
    Attached Files Attached Files

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: from sqlquery to qstringlist

    The errors are obvious in your posted code... you should learn to use the tools you already have to find it. Have you single stepped through the code in your debugger? Have you checked the error returns from QSqlQuery::exec() and QSqlQuery::lastError()? Have you looked at the database that is actually created? What tables exist? What tables are you trying to use in your code?

  3. #3
    Join Date
    Jun 2011
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: from sqlquery to qstringlist

    Hi all,

    I am facing similar problem.

    I have create the application using forms (ui file) using qtcreator.
    when i try to add a list to the combo-box, its added but not displaying.

    I have cross verified for the existance of the entries in the combo-box with count() and displays the
    correct count i inserted and also it gives the correct values which fetched and displayed on terminal.

    Can any one help me out with a method to display the same list in the application.

    Thanks,
    Uday Pratap

  4. #4
    Join Date
    Oct 2015
    Posts
    3
    Qt products
    Qt5
    Platforms
    Unix/X11 Android

    Default Re: from sqlquery to qstringlist

    Qt Code:
    1. QSqlQuery *query = new QSqlQuery("select "+filed_name+" from "+table_name);
    2. while(query->next())
    3. {
    4. combobox.addItem(query->value(0).toString());
    5. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by tokimay; 4th February 2016 at 17:55.

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

    Default Re: from sqlquery to qstringlist

    Why on earth did you post that?

    Not only is it wrong on many levels, it is what the original poster already had without any of the bad things.

    Cheers,
    _

Similar Threads

  1. Help QStringList
    By pcoliver in forum Qt Programming
    Replies: 0
    Last Post: 15th September 2011, 11:15
  2. sqlQuery executing return nothing
    By ar_a24 in forum Qt Programming
    Replies: 0
    Last Post: 26th February 2011, 07:04
  3. SQLQUERY - column value retrun problem
    By damodharan in forum Qt Programming
    Replies: 7
    Last Post: 27th May 2010, 08:09
  4. Casting in a select sqlQuery
    By Kesy in forum Qt Programming
    Replies: 3
    Last Post: 25th November 2008, 16:12
  5. Replies: 7
    Last Post: 2nd June 2006, 13:48

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.