Results 1 to 8 of 8

Thread: How send result query database to List<QString>

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2016
    Posts
    9
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How send result query database to List<QString>

    I would like send value from two column table Qtableview (value int and varchar) to Qcombobox

    query: select kod_lekarstwa, nazwa from lekarstwo;


    I think about such loop:

    for (list<QString>::iterator it=diseases.begin(); it != diseases.end(); ++it)
    {
    ui->diseasecomboBox->addItem(*it);
    }

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

    Default Re: How send result query database to List<QString>

    You can use QString::number() to convert the int value to a string and then use the + operator to concatenate with the second part.
    That string can then easily be appended to a QStringList (which is a QList<QString>)

    Cheers,
    _

  3. #3
    Join Date
    Jan 2016
    Posts
    9
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How send result query database to List<QString>

    on start we try to do on the one column , only String values
    select nazwa from lekarstwo;

    it works, but I don't know how appended result query to QList
    Qt Code:
    1. QList<QString> list;
    2. list << "item1" << "item2" << "item3";
    3.  
    4. foreach( s, list )
    5. {
    6. qDebug() << s;
    7. ui->comboBoxmedicine->addItem(s);
    8. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by bartes19; 10th January 2016 at 12:19.

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

    Default Re: How send result query database to List<QString>

    I am afraid I don't understand.
    Your code already adds strings to the list, i.e. you already know how the << operator works.

    Cheers,
    _

  5. #5
    Join Date
    Jan 2016
    Posts
    9
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How send result query database to List<QString>

    Something like that?

    list << query.exec("select kod_lekarstwa, nazwa from lekarstwo;");

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

    Default Re: How send result query database to List<QString>

    exec() returns a bool.

    You want to loop over the results. See the example in the documentation for QSqlQuery.

    Cheers,
    _

Similar Threads

  1. Filling a ComboBox with SQL query result
    By igr in forum Qt Programming
    Replies: 1
    Last Post: 1st September 2014, 17:16
  2. how to send sqlite query CREATE TRIGGER in qt application
    By abdul_moiz in forum Qt Programming
    Replies: 2
    Last Post: 10th June 2011, 06:07
  3. query regarding installing a database along with App
    By chandantheracer in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 3rd June 2011, 15:27
  4. How to find result of a query in qsqlite?
    By newtowindows in forum Qt Programming
    Replies: 1
    Last Post: 28th October 2009, 11:40
  5. Replies: 1
    Last Post: 19th August 2007, 19:50

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.