Results 1 to 4 of 4

Thread: Matching Data from QStringList

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2011
    Location
    Toronto Canada
    Posts
    97
    Thanks
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Matching Data from QStringList

    I have an SQL Query that retrieved data into a QStringList (data1,data2) when i import the results from that value position ie: data1 << sqlquery.value(3).toString(); and data2 << sqlquery.value(6).toString();

    data1 contains:
    36
    50

    data2 contains:
    f5d7e.avi
    c2d96.png

    now assuming that the first string in the list would be 36 for data1 and f5d7e.avi for data2

    now if i want to say

    Qt Code:
    1. QStringList data1,data2;
    2. data1 << "36" << "50";
    3. data2 << "f5d7e.avi" << "c2d96.png";
    4.  
    5. int data1Size = data1.size();
    6. int data2Size = data2.size();
    7. QString data1String, data2String;
    8.  
    9. for(int i = 0; i < data1Size; i++){
    10. data1String = data1.at(i);
    11. for(int f = 0; f < data2Size; f++){
    12. data2String = data2.at(f);
    13. }
    14. }
    15. qDebug() << "Data1: " +data1String +" Data2: " +data2String;
    To copy to clipboard, switch view to plain text mode 

    now how do i get the correct information on 1 line like

    Data1: 36 Data2: f5d7e.avi
    Data1: 50 Data2: c2d96.png

    Thanks for your assistance...

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Matching Data from QStringList

    If that is the only information you want to get out of the database then use the SELECT statement (see for concat function). And the right loop would be
    Qt Code:
    1. QStringList result;
    2. for(int i = 0; i < data1Size; i++){ // assuming data1Size == data2Size
    3. result << "Data1:" << data1.at(i) << " Data2:" << data2.at(i);
    4. }
    5. qWarning() << result;
    6. qWarning() << result.join("; ");
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Oct 2011
    Location
    Toronto Canada
    Posts
    97
    Thanks
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Matching Data from QStringList

    now how would i be able to do something like this

    data1 contains
    36
    50

    data2 contains
    111.avi
    1111.png
    222.avi
    2222.png

    now from my sql query 111.avi & 1111.png belong to 36 and 222.avi & 2222.png belong to 50

    how would i accomplish such task?

  4. #4
    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: Matching Data from QStringList

    Define the rules that connects an entry in the first list with an entry, or entries, in the second. If you cannot, and I suspect this to be the case, then you need to look at the way you are getting the data out of the database. RDBMS systems are designed to do related queries, why not use it.

Similar Threads

  1. no matching function error
    By arpspatel in forum Qt Programming
    Replies: 4
    Last Post: 16th October 2009, 15:47
  2. No Matching function to call...
    By weepdoo in forum Qt Programming
    Replies: 2
    Last Post: 7th November 2008, 17:30
  3. Partial matching of regex
    By ehamberg in forum Qt Programming
    Replies: 1
    Last Post: 28th May 2008, 20:13
  4. pattern [image] matching
    By rachana in forum Qt Programming
    Replies: 1
    Last Post: 26th February 2007, 13:31
  5. Replies: 7
    Last Post: 2nd June 2006, 12: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
  •  
Qt is a trademark of The Qt Company.