Results 1 to 13 of 13

Thread: How to set a signal before shutdown?

  1. #1
    Join Date
    Aug 2011
    Posts
    25
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default How to set a signal before shutdown?

    Hello!

    I'm using qextserialport for sending data. In my program I have no GUI. The progam will automatic start in the background when the PC is started. I need to set RTS low before shutdown the program. The program will be shutdown when the power turn off. In my testprogram I push x-button in Application Output.

    Is it possible to catch some shutdownsignal so I can call

    Qt Code:
    1. CommPort->setRts(0);
    To copy to clipboard, switch view to plain text mode 

    before the PC is shutdown. It is possible to use another connect for a shutdown signal?

    My main program is like, I have deleted some code that I think are irrelevant:

    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. QCoreApplication a(argc, argv);
    4. createDatabaseConnection();
    5.  
    6. // Initiate all modules
    7. FlexiBlinkRX flexiBlinkRx;
    8. FBtoFLTP FBtoFLTP1;
    9. FilterEngine filterEngine;
    10. smsThread SMSThread;
    11.  
    12. SMSThread.start();
    13.  
    14. // Connect all signals between modules
    15. FBtoFLTP1.connect (&flexiBlinkRx, SIGNAL(incommingDataSignal()), SLOT(startTask()));
    16. filterEngine.connect (&FBtoFLTP1, SIGNAL(inputToQueueSignal()), SLOT(checkqFilterQueue()));
    17.  
    18. // Start executing
    19. a.exec();
    20.  
    21. SMSThread.quit();
    22. SMSThread.wait();
    23.  
    24. flexiBlinkRx.CommPort->setRts(0);
    25. return 0;
    26. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: How to set a signal before shutdown?

    I think the aboutToQuit signal is what you are looking for.

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to set a signal before shutdown?

    I think it is pointless. If the power is going off then the state of RTS will surely follow into electrical oblivion.

  4. #4
    Join Date
    Aug 2011
    Posts
    25
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to set a signal before shutdown?

    I use external power supply for the unit where I use the signal, because I need 9V. It's the reason why I need to shutdown the RTS-signal.
    I have tried the following in main:

    Qt Code:
    1. flexiBlinkRx.connect (&a, SIGNAL(aboutToQuit()), SLOT(shutDownRts1()));
    To copy to clipboard, switch view to plain text mode 

    But this seems not to work.
    I have put in the sentence together with the other connect-sentences.
    Can anybody help me?

  5. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to set a signal before shutdown?

    Is the slot never called, or the slot called but not working?
    Does the code setting RTS require a Qt event loop to process the request?
    Can you achieve the same thing by simply putting the RTS code in the flexiBlinkRx destructor?

    It may be that Windows (It is Windows right?) is terminating the application forcibly and the aboutToQuit() signal is not sent.

    You could try using the QCoreApplication::winEventFilter() to capture the WM_ENDSESSION and/or WM_QUERYENDSESSION message.

  6. #6
    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: How to set a signal before shutdown?

    Provide the third argument to connect() explicitly.
    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.


  7. #7
    Join Date
    Aug 2011
    Posts
    25
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to set a signal before shutdown?

    I use Ubuntu Virtual Machine.
    The slot is never called.
    I have also tried to set the RTS signal in the destructor, but no result.
    Wysota: I don't understand what yiou mean. Can you please explain?

  8. #8
    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: How to set a signal before shutdown?

    Where is the "shutDownRts1" slot implemented?
    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.


  9. #9
    Join Date
    Aug 2011
    Posts
    25
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to set a signal before shutdown?

    It is implemented in flexiBlinkRx.cpp as a public slot.

  10. #10
    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: How to set a signal before shutdown?

    Does the aboutToQuit() signal gets emitted at all? How are you testing your code?
    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.


  11. #11
    Join Date
    Aug 2011
    Posts
    25
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to set a signal before shutdown?

    It seems that the aboutToQuit() signal never gets emitted.
    I am testing my code by debugging and running the code.
    For stopping the program I push the X-button in the Application window.

  12. #12
    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: How to set a signal before shutdown?

    Maybe your program crashes instead of quitting?
    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.


  13. #13
    Join Date
    Aug 2011
    Posts
    25
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to set a signal before shutdown?

    Yes, I think so.

    Do you know if I then can catch some signals so I can set the RTS-signal to 0?

Similar Threads

  1. shutdown the system with progress bar
    By baobui in forum Newbie
    Replies: 1
    Last Post: 17th May 2011, 08:01
  2. Replies: 0
    Last Post: 14th December 2010, 00:39
  3. Shutdown on Mac failing
    By ntp in forum Qt Programming
    Replies: 4
    Last Post: 11th December 2010, 01:41
  4. Finalization on system shutdown
    By nomadoro in forum Qt Programming
    Replies: 4
    Last Post: 30th October 2009, 19:30
  5. closeEvent preventing shutdown
    By gfunk in forum Qt Programming
    Replies: 2
    Last Post: 16th October 2007, 19:41

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.