Results 1 to 6 of 6

Thread: [open] HowTo work with QPairs in a QList

  1. #1
    Join Date
    Apr 2014
    Posts
    116
    Thanks
    8
    Qt products
    Qt5
    Platforms
    MacOS X

    Default [open] HowTo work with QPairs in a QList

    Hi,

    I try to use QPair to store connected data in a QList:
    Qt Code:
    1. QList<QPair<QString, int> > status;
    2.  
    3. ...
    4.  
    5. status.append(QPair("test", 0));
    To copy to clipboard, switch view to plain text mode 
    But I get an error:
    cannot refer to class template 'QPair' without a template argument list

    What does this mean?

    If I click on "template is declared here" in the error log it goes to QGRAPHICSITEMANIMATION_H and points to this line:
    template <class T1, class T2> struct QPair;

    I copied this from an example in the documentation so I am really confused that it is not working.

  2. #2
    Join Date
    Oct 2013
    Posts
    41
    Thanks
    1
    Thanked 8 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: [open] HowTo work with QPairs in a QList

    From: http://qt-project.org/doc/qt-4.8/qpair.html#QPair-2

    Related Non-Members
    QPair<T1, T2> qMakePair ( const T1 & value1, const T2 & value2 )
    Returns a QPair<T1, T2> that contains value1 and value2. Example:
    QList<QPair<int, double> > list;
    list.append(qMakePair(66, 3.14159));
    This is equivalent to QPair<T1, T2>(value1, value2), but usually requires less typing.
    So try it with
    status.append(qMakePair("test",0))
    or
    status.append(QPair<QString, int>("test",0))

  3. #3
    Join Date
    Apr 2014
    Posts
    116
    Thanks
    8
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: [open] HowTo work with QPairs in a QList

    I tried status.append(qMakePair("test", 0)); and that looks better know but I still get an error:
    Qt Code:
    1. .../Qt/5.2.1/clang_64/lib/QtCore.framework/Headers/qpair.h:57: Error: array initializer must be an initializer list or string literal
    2. QPair(const T1 &t1, const T2 &t2) : first(t1), second(t2) {}
    3.  
    4. .../Qt/5.2.1/clang_64/lib/QtCore.framework/Headers/qpair.h:117: in instantiation of member function 'QPair<char [10], int>::QPair' requested here
    5. return QPair<T1, T2>(x, y);
    To copy to clipboard, switch view to plain text mode 
    What is that supposed to mean?

  4. #4
    Join Date
    Oct 2013
    Posts
    41
    Thanks
    1
    Thanked 8 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: [open] HowTo work with QPairs in a QList

    looks like it didn't interpret "test" as a QString.
    in instantiation of member function 'QPair<char [10], int>::QPair' requested here
    Try:
    status.append(qMakePair(QString("test"),0))

  5. The following user says thank you to sulliwk06 for this useful post:

    KeineAhnung (5th May 2014)

  6. #5
    Join Date
    Apr 2014
    Posts
    116
    Thanks
    8
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: [open] HowTo work with QPairs in a QList

    Thanks for the help! I need to get better in reading error =)

  7. #6
    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: [open] HowTo work with QPairs in a QList

    Just saying: in a lot of cases it is way easier to just use a custom struct with two named fields instead of a pair

    Cheers,
    _

Similar Threads

  1. Replies: 15
    Last Post: 2nd July 2013, 08:45
  2. HowTo get work Microsoft VS 2010 and Qt Visual Studio Add-in?
    By NewLegend in forum Installation and Deployment
    Replies: 15
    Last Post: 17th October 2010, 18:15
  3. Replies: 6
    Last Post: 28th July 2010, 11:20

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.