Results 1 to 2 of 2

Thread: QTest and QEventLoop inside a library

  1. #1
    Join Date
    Feb 2011
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QTest and QEventLoop inside a library

    Hi all,
    inside a library I have code like:
    Qt Code:
    1. QNetworkReply* AIDAW::getRequest(const QString& url){
    2. QEventLoop loop;
    3. QTimer timer;
    4.  
    5. QNetworkRequest request(url);
    6. QNetworkReply *reply = this->network_manager->get(request);
    7.  
    8. QObject::connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
    9. QObject::connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
    10.  
    11. timer.start(TIMEOUT);
    12. loop.exec();
    13.  
    14. if(timer.isActive() == false){
    15. //manage the timeout
    16. }
    17.  
    18. return reply;
    19.  
    20. }
    To copy to clipboard, switch view to plain text mode 

    If I try to write a QTest Project using this library I get this error:
    Qt Code:
    1. ********* Start testing of MyProject *********
    2. Config: Using QTest library 4.7.0, Qt 4.7.0
    3. PASS : AIDATest::initTestCase()
    4. QEventLoop: Cannot be used without QApplication
    5. QObject::connect: Cannot connect (null)::aboutToQuit() to QNativeWifiEngine::clo
    6. seHandle()
    7. QObject::startTimer: QTimer can only be used with threads started with QThread
    8. QObject::startTimer: QTimer can only be used with threads started with QThread
    To copy to clipboard, switch view to plain text mode 

    the main of the test project is managed by QTEST_MAIN(MyTestClass) macro
    --
    MementoMori

  2. #2
    Join Date
    Jul 2009
    Location
    Enschede, Netherlands
    Posts
    462
    Thanked 69 Times in 67 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTest and QEventLoop inside a library

    It is unwise to start an event loop within an event loop. The issue you run into right now could be one you run into when running a program using the library. In this case you should probably start a thread (with an event loop then) and wait until the thread has finished doing it's job. Alternatively you could try a different approach, but that would require more knowledge of the nature of your system. See also http://labs.qt.nokia.com/2010/02/23/unpredictable-exec/.
    Horse sense is the thing that keeps horses from betting on people. --W.C. Fields

    Ask Smart Questions

Similar Threads

  1. Wrap a static QT library inside an XPCOM component ?
    By Paul_Xul in forum Qt Programming
    Replies: 2
    Last Post: 3rd August 2010, 07:16
  2. How to use QEventLoop?
    By MorrisLiang in forum Newbie
    Replies: 3
    Last Post: 13th May 2010, 16:23
  3. qprocess or qeventloop
    By knishaq in forum Qt Programming
    Replies: 1
    Last Post: 20th December 2009, 10:14
  4. static QEventLoop strange behavior
    By SABROG in forum Qt Programming
    Replies: 2
    Last Post: 29th July 2009, 12:04
  5. error PRJ0019 while using qtest library
    By rajeshs in forum Qt Programming
    Replies: 4
    Last Post: 21st November 2007, 10:15

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.