PDA

View Full Version : Unable to terminate QCoreApplication



yagabey
2nd February 2009, 19:19
Hello,
I am trying to connect to a host in my core application. If socket can connect to the host; no problem...But if it cannot resolve the hostname, the application stucks there. The application doesn't crash; but just refuses to exit, after that point...

I tried QCoreApplication::exit() and standart c library exit() functions, none could terminate the program. Is there any way to exit the program, no matter how?

that is the stubborn connecttohost function:

d->socket->connectToHost( d->pop3_server , d->port );

I tried (not good but, need it.. ):

QTimer::singleShot(20000, this, SLOT(exitnow()));

my slot:

void Pop3::exitnow()
{
QCoreApplicaition::exit(0);
}

also tried:

void Pop3::exitnow()
{
exit(0);
}

I debugged the application and saw that the exitnow() slot is called;but the application doesn't terminate.

wysota
3rd February 2009, 00:35
Your application is hanging at the resolving code (probably somewhere in the operating system) and it can't get back to the event loop thus the exit code is not executed. This is actually the fault of your operating system as it doesn't notify the application it can't resolve the host and instead it keeps trying. I don't think there is much you can do beside pressing CTRL+C.

yagabey
3rd February 2009, 06:48
I see. But i will use that application on an embedded system without a keyboard interface(works with voice commands). Isn't there any safer method to overcome this issue.

yagabey
3rd February 2009, 10:54
I connected the error() signal of socket to my erroroccured() slot:


void Pop3::errorOccured(QAbstractSocket::SocketError error)
{
d->socket->abort();//critical part
exit(0);
}

It terminates the application now...