PDA

View Full Version : How to set a signal before shutdown?



inger
30th May 2012, 07:49
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


CommPort->setRts(0);

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:



int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
createDatabaseConnection();

// Initiate all modules
FlexiBlinkRX flexiBlinkRx;
FBtoFLTP FBtoFLTP1;
FilterEngine filterEngine;
smsThread SMSThread;

SMSThread.start();

// Connect all signals between modules
FBtoFLTP1.connect (&flexiBlinkRx, SIGNAL(incommingDataSignal()), SLOT(startTask()));
filterEngine.connect (&FBtoFLTP1, SIGNAL(inputToQueueSignal()), SLOT(checkqFilterQueue()));

// Start executing
a.exec();

SMSThread.quit();
SMSThread.wait();

flexiBlinkRx.CommPort->setRts(0);
return 0;
}

Zlatomir
30th May 2012, 08:03
I think the aboutToQuit (http://qt-project.org/doc/qt-4.8/qcoreapplication.html#aboutToQuit) signal is what you are looking for.

ChrisW67
30th May 2012, 09:37
I think it is pointless. If the power is going off then the state of RTS will surely follow into electrical oblivion.

inger
31st May 2012, 07:09
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:


flexiBlinkRx.connect (&a, SIGNAL(aboutToQuit()), SLOT(shutDownRts1()));

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

ChrisW67
31st May 2012, 09:31
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.

wysota
31st May 2012, 10:12
Provide the third argument to connect() explicitly.

inger
31st May 2012, 14:00
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?

wysota
31st May 2012, 14:29
Where is the "shutDownRts1" slot implemented?

inger
1st June 2012, 06:38
It is implemented in flexiBlinkRx.cpp as a public slot.

wysota
1st June 2012, 09:35
Does the aboutToQuit() signal gets emitted at all? How are you testing your code?

inger
1st June 2012, 10:18
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.

wysota
1st June 2012, 17:15
Maybe your program crashes instead of quitting?

inger
4th June 2012, 07:30
Yes, I think so.

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