Results 1 to 5 of 5

Thread: Using QPair in QTest

  1. #1
    Join Date
    Jan 2010
    Location
    Perth, Australia
    Posts
    37
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Using QPair in QTest

    Hi, is it possible to use QPairs as test values? I'm running into some trouble:

    Qt Code:
    1. void function_data()
    2. {
    3. QTest::addColumn<QDate>("testDate");
    4. QTest::addColumn< QPair<QDate,QDate> >("expectedOutputs");
    5.  
    6. // newRow...
    7. }
    8.  
    9. void function()
    10. {
    11. QFETCH(QDate, testDate);
    12. QFETCH(QPair<QDate,QDate>, expectedOutputs);
    13.  
    14. // QCOMPARE...
    15. }
    To copy to clipboard, switch view to plain text mode 

    My compiler seems to have issues with the comma in the QPair template and complains
    Qt Code:
    1. error: macro "QFETCH" passed 3 arguments, but takes just 2
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Using QPair in QTest


  3. #3
    Join Date
    Jan 2010
    Location
    Perth, Australia
    Posts
    37
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Using QPair in QTest

    Quote Originally Posted by tbscope View Post
    Thanks tbscope. Unfortunately,
    Qt Code:
    1. Q_DECLARE_METATYPE(QPair<QDate,Ddate>)
    To copy to clipboard, switch view to plain text mode 
    leads to:
    Qt Code:
    1. error: macro "Q_DECLARE_METATYPE" passed 2 arguments, but takes just 1
    To copy to clipboard, switch view to plain text mode 

    I'm guessing that the preprocessor (I'm using GCC 4.5.0 on Windows and Qt 4.6.2) doesn't like special usages of commas inside macros...? addColumn() seemed ok, but Q_DECLARE_METATYPE and QFETCH both balked.

    My current workaround is to store pair.first and pair.second in separate columns, and do element-wise comparisons. :-/ (My container is actually QList< QPair<QDate,QDate> >, split such that each test row row contains two parallel QList<QDate>).

    It's working fine so far, but if there's a neater way to do it, please let me know!
    Last edited by hackerNovitiate; 16th November 2010 at 05:27. Reason: Clarification

  4. #4
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Using QPair in QTest

    You can try a typedef.

    As far as I know, it should be possible to use QPair or QHash or QMap, but I'm not behind a development machine, so I can't test it.

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

    hackerNovitiate (16th November 2010)

  6. #5
    Join Date
    Jan 2010
    Location
    Perth, Australia
    Posts
    37
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Using QPair in QTest

    Quote Originally Posted by tbscope View Post
    You can try a typedef.
    Qt Code:
    1. typedef QList< QPair<QDate,QDate> > PairList;
    2. Q_DECLARE_METATYPE(PairList)
    To copy to clipboard, switch view to plain text mode 
    ...worked like a charm. Thanks!

Similar Threads

  1. How to qSort a Qlist of QPair?
    By Trader in forum Qt Programming
    Replies: 2
    Last Post: 7th July 2010, 19:04
  2. Replies: 10
    Last Post: 20th June 2010, 22:29
  3. Replies: 4
    Last Post: 12th October 2009, 19:36
  4. using QPair in QVector
    By damonlin in forum Qt Programming
    Replies: 5
    Last Post: 28th January 2009, 09:29
  5. QTest
    By Mordicus in forum Qt Programming
    Replies: 1
    Last Post: 25th July 2006, 10:35

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.