Results 1 to 5 of 5

Thread: QTestLib: check if the signal has a std::string type

  1. #1
    Join Date
    Nov 2007
    Posts
    36
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QTestLib: check if the signal has a std::string type

    Hi,

    I found the next code reading the documentation:

    Qt Code:
    1. QSignalSpy spy(myCustomObject, SIGNAL(mySignal(int, QString, double)));
    2.  
    3. myCustomObject->doSomething(); // trigger emission of the signal
    4.  
    5. QList<QVariant> arguments = spy.takeFirst();
    6. QVERIFY(arguments.at(0).type() == QVariant::Int);
    7. QVERIFY(arguments.at(1).type() == QVariant::QString);
    8. QVERIFY(arguments.at(2).type() == QVariant::double);
    To copy to clipboard, switch view to plain text mode 

    But I'm having many problems when I want to check if the signal has a std::string type.

    Any idea?

    Thanks.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTestLib: check if the signal has a std::string type

    Did you register std::string with QVariant?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Nov 2007
    Posts
    36
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTestLib: check if the signal has a std::string type

    Yes, I did that.

    Now I have the line QList<QVariant> arguments = spy.takeFirst(); working right.

    Following with the code, how can I convert "arguments.at(1)" (if at(1) is a std::string) to std::string?

    Using QVariant, the method toString() is returning an empty string, so I cannot use toString().toStdString().

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTestLib: check if the signal has a std::string type

    Qt Code:
    1. QVariant var = ...;
    2. std::string str = var.value<std::string>();
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    tarod (14th December 2012)

  6. #5
    Join Date
    Nov 2007
    Posts
    36
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Thumbs up Re: QTestLib: check if the signal has a std::string type

    I've just find the same solution.

    Thanks anyway!

Similar Threads

  1. String similarity check
    By sedi in forum Qt Programming
    Replies: 2
    Last Post: 23rd June 2012, 19:07
  2. best way to check for data type
    By timmu in forum Qt Programming
    Replies: 1
    Last Post: 4th January 2012, 10:40
  3. Using ANSI string type
    By kahahn in forum Newbie
    Replies: 1
    Last Post: 21st June 2009, 00:52
  4. qregexp to check string
    By mattia in forum Newbie
    Replies: 3
    Last Post: 19th February 2008, 15:13
  5. How to check if a string starts with a substring?
    By lni in forum Qt Programming
    Replies: 3
    Last Post: 18th April 2007, 01:36

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.