Results 1 to 4 of 4

Thread: Qt signals/slots dll for non-Qt app

  1. #1
    Join Date
    Oct 2014
    Posts
    3
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Qt signals/slots dll for non-Qt app

    Hi All,

    I have a problem with the signal/slots for my dll.


    Here is my setup:

    1) MySystemWrapper.dll is a c wrapper that can be called from python (or other app.. but for now I use python to debug).
    The connect() function calls the Qt dll that cannot be called with other apps.

    Qt Code:
    1. bool connect(){
    2. QAppPriv::pApp = new QCoreApplication(QAppPriv::argc, QAppPriv::argv); //to handle signals and slots
    3. mSystem = new mySystem();
    4.  
    5. return true;
    6. }
    To copy to clipboard, switch view to plain text mode 

    2) In the mySystem.dll the constructor looks like this:

    Qt Code:
    1. MySystem::MySystem()
    2. {
    3.  
    4. QThread *thread = new QThread;
    5.  
    6. //USB HID interface
    7. plugNPlay = new HID_PnP();
    8. plugNPlay->moveToThread(thread);
    9. plugNPlay->start();
    10.  
    11.  
    12.  
    13. ////signal slots test
    14.  
    15. processEventsTmr = new QTimer(this);
    16. processEventsTmr->setInterval(1000); //x ms between each process events
    17. connect(processEventsTmr,SIGNAL(timeout()), this, SLOT(processMyEvents()));
    18.  
    19. }
    To copy to clipboard, switch view to plain text mode 

    The problem I have is that processMyEvents() is never called. So the signal/slot does not work in the MySystem object.

    HOWEVER, the signal/slot ARE WORKING in the plugNPlay object.

    I think my problem is with the way new QCoreApplication is called but I can figure it out.

    I have read this over and over again!

    Thanks

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Qt signals/slots dll for non-Qt app

    So where are you calling QCoreApplication::exec() on your application instance? If the event loop isn't running, events don't get processed. You also can't have more than one QCoreApplication instance, but your connect() method will create a new one every time it is called.

    I think you need to read the stackoverflow post at least one more time, and follow the suggestions exactly.

  3. The following user says thank you to d_stranz for this useful post:

    bareil76 (24th October 2014)

  4. #3
    Join Date
    Oct 2014
    Posts
    3
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: Qt signals/slots dll for non-Qt app

    Ok..

    here is what I have now.

    What works:
    a) The plugNPlay object has timers and connects that work.
    b) connect(plugNPlay, SIGNAL(JustConnected(bool)),this,SLOT(initialize(b ool)), Qt::QueuedConnection); is also working
    c) connect(retryTmr,SIGNAL(timeout()), this, SLOT(handleNoResponse())); also works.

    What doesn't work:
    a) In the initialize(bool) slot.. I have retryTmr->start();... the system complains that:

    QObject::killTimer: timers cannot be stopped from another thread
    QObject::startTimer: timers cannot be started from another thread



    1) First MySystemWrapper which is called first. I had to put the MySystem object in another thread because if I don't.. nothing works!

    Qt Code:
    1. bool MYSYSTEMWRAPPERSHARED_EXPORT connect(){
    2.  
    3. mMySystem = new MySystem();
    4. mMySystem->moveToThread(thread2);
    5. thread2->start();
    6. QMetaObject::invokeMethod(mMySystem, "run", Qt::QueuedConnection);
    7.  
    8.  
    9. return true;
    10. }
    To copy to clipboard, switch view to plain text mode 

    2) Then, the MySystem class is called from the above. The constructor is only to start the QApp. With the signal that will call exec().... ONLY then I call the run() that will created my program objects.

    Qt Code:
    1. MySystem::MySystem(QObject *parent) :
    2. QObject(parent)
    3. {
    4. if (QAppPriv::pThread == NULL)
    5. {
    6. qDebug()<< "QAppPriv::pThread created";
    7. // Separate thread for application thread
    8. QAppPriv::pThread = new QThread();
    9. // Direct connection is mandatory
    10. QObject::connect(QAppPriv::pThread, SIGNAL(started()), this, SLOT(OnExec()), Qt::DirectConnection);
    11. QAppPriv::pThread->start();
    12. }
    13.  
    14.  
    15. }
    16. void MySystem::OnExec(){
    17. if (QCoreApplication::instance() == NULL)
    18. {
    19. qDebug()<< "QAppPriv::pApp created";
    20. QAppPriv::pApp = new QCoreApplication(QAppPriv::argc, QAppPriv::argv);
    21. QAppPriv::pApp->exec();
    22. if (QAppPriv::pApp)
    23. delete QAppPriv::pApp;
    24. }
    25. }
    26.  
    27.  
    28.  
    29. void MySystem::run(){
    30. QThread *thread = new QThread;
    31. plugNPlay = new HID_PnP();
    32. plugNPlay->moveToThread(thread);
    33.  
    34. isConnected = false;
    35.  
    36.  
    37.  
    38. retryTmr = new QTimer(this);
    39. retryTmr->setSingleShot(true);
    40. retryTmr->setInterval(10); //10ms between retry
    41. connect(retryTmr,SIGNAL(timeout()), this, SLOT(handleNoResponse()));
    42.  
    43.  
    44.  
    45. connect(plugNPlay, SIGNAL(JustConnected(bool)),this,SLOT(initialize(bool)),
    46. Qt::QueuedConnection);
    47. }
    To copy to clipboard, switch view to plain text mode 

  5. #4
    Join Date
    Oct 2014
    Posts
    3
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: Qt signals/slots dll for non-Qt app

    The above worked... I had another problem. SOLVED

Similar Threads

  1. Replies: 2
    Last Post: 18th April 2013, 13:15
  2. Signals and Slots
    By ggdev001 in forum Qt Programming
    Replies: 6
    Last Post: 20th February 2013, 13:07
  3. QT SIGNALS and SLOTS
    By beginQT in forum Newbie
    Replies: 7
    Last Post: 23rd September 2011, 15:40
  4. Signals and Slots
    By 83.manish in forum Qt Programming
    Replies: 3
    Last Post: 30th June 2008, 11:31
  5. Signals and Slots
    By merry in forum Qt Programming
    Replies: 4
    Last Post: 22nd February 2007, 09:11

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.