Results 1 to 6 of 6

Thread: Connecting signal from main.cpp to application.cpp

  1. #1
    Join Date
    Sep 2010
    Location
    Ontario Canada
    Posts
    23
    Thanks
    5
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Symbian S60 Maemo/MeeGo

    Default Connecting signal from main.cpp to application.cpp

    Excuse my c++ ignorance.
    I am trying to attach the QCoreApplication::aboutToQuit() signal to my save function so I can save some data after the user closes the app on BB10 OS. My QCloseEvent doesn't get called on BB10 when the user swipes up and closes the app so I am trying this approach as suggested in the docs for BB10.
    According to the docs for BB10 I have 3 seconds after the signal aboutToQuit() is emited which should be plenty of time for QSettings to save my data.
    I put this line in my main.cpp
    Qt Code:
    1. QObject::connect(&a, SIGNAL(aboutToQuit()), &w, SLOT(save()));
    To copy to clipboard, switch view to plain text mode 
    Here is my entire main.cpp for referance:
    Qt Code:
    1. #include <QtGui/QApplication>
    2. //#include <QtGui/QGuiApplication>
    3. #include "biologger.h"
    4. //#include <bb/Application>
    5.  
    6. int main(int argc, char *argv[])
    7. {
    8. QApplication a(argc, argv);
    9.  
    10. a.setOrganizationName("HeronBoy");
    11. a.setOrganizationDomain("theHerons.ca");
    12. a.setApplicationName("Bio Logger");
    13.  
    14. bioLogger w;
    15. w.showMaximized();
    16. QObject::connect(&a, SIGNAL(aboutToQuit()), &w, SLOT(save()));
    17. return a.exec();
    18. }
    To copy to clipboard, switch view to plain text mode 
    But my save function is never called?
    The way I understand it the signal should be accessible from any public slots in the application and I have my save function declared as a pubic slot
    Qt Code:
    1. public slots:
    2. void save();
    To copy to clipboard, switch view to plain text mode 
    .

    Any help or insight on how to troubleshoot this would be appreciated.
    Cheers,
    Jon

  2. #2
    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: Connecting signal from main.cpp to application.cpp

    Do you get any runtime error at startup, i.e. does the connect work (it will print a warning if it does not).
    It looks good but e.g. the class bioLogger could miss the Q_OBJECT macro, etc.

    Another option you could try if you don't need the event loop

    Qt Code:
    1. w.showMaximize()
    2.  
    3. int ret = app.exec();
    4.  
    5. w.save();
    6.  
    7. return ret;
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

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

    Jon Heron (6th March 2014)

  4. #3
    Join Date
    Sep 2010
    Location
    Ontario Canada
    Posts
    23
    Thanks
    5
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Symbian S60 Maemo/MeeGo

    Default Re: Connecting signal from main.cpp to application.cpp

    Thanks!
    No, there is no error messages, not sure what the problem is... Is there any way to qDebug() << the signal from the app.cpp to see if its getting emitted?
    Either way your event loop works great and its now saving properly!
    Thanks again!
    Cheers,
    Jon

  5. #4
    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: Connecting signal from main.cpp to application.cpp

    Quote Originally Posted by Jon Heron View Post
    No, there is no error messages, not sure what the problem is... Is there any way to qDebug() << the signal from the app.cpp to see if its getting emitted?
    Not without changing Qt I think.

    Quote Originally Posted by Jon Heron View Post
    Either way your event loop works great and its now saving properly!
    Ah, great

    Cheers,
    _

  6. #5
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Connecting signal from main.cpp to application.cpp

    Read about QSignalSpy class.

  7. #6
    Join Date
    Apr 2013
    Location
    Prague
    Posts
    258
    Thanks
    3
    Thanked 65 Times in 59 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Connecting signal from main.cpp to application.cpp

    The usual way of checking whether a slot is called is putting a break (or qDebug() or something similar) in the slot handler and seeing whether you reach the breakpoint (or whether you get a message or something similar). If you cannot modify bioLogger then create a class, say DebugClass, give the class a slot, say DebugSlot() and connect the signal to the DebugSlot(). Put qDebug() in the DebugSlot() and let DebugSlot() call w.save(). Run and see what will happen.

Similar Threads

  1. Connecting signal and slot by name
    By grayfox in forum Qt Programming
    Replies: 1
    Last Post: 22nd July 2011, 09:00
  2. Replies: 1
    Last Post: 14th March 2011, 10:21
  3. dynamic signal connecting
    By donglebob in forum Qt Programming
    Replies: 4
    Last Post: 19th November 2008, 09:58
  4. Connecting signal to button
    By steg90 in forum Qt Programming
    Replies: 8
    Last Post: 13th December 2007, 10:37
  5. Connecting signal to form that is closing
    By steg90 in forum Qt Programming
    Replies: 3
    Last Post: 18th May 2007, 07:54

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.