I have a thread I run in my console app that allows the user to quit at any time by typing 'q' and pressing enter. The thread gracefully ends when the user does this because it breaks out of my loop and the run() function terminates. However, there are certain other situations in which I want to close the app (e.g. some event occurs), but I can't terminate the thread because it is always blocked on the readLine() call so I get a warning message upon quitting the app saying something like "Quit application while QThread still running..."
Is there a way around this to quit gracefully and not receive this warning?
class ConsoleReader
: public QThread {
public:
{
QThread::setTerminationEnabled( true );
}
virtual void run()
{
forever
{
if( !line.isNull() )
{
if( line.toLower() == "q" )
{
break;
}
}
}
}
};
class ConsoleReader : public QThread
{
public:
ConsoleReader( QObject * parent = 0 ) : QThread( parent )
{
QThread::setTerminationEnabled( true );
}
virtual void run()
{
QTextStream qin( stdin, QFile::ReadOnly );
forever
{
QString line = qin.readLine();
if( !line.isNull() )
{
if( line.toLower() == "q" )
{
break;
}
}
}
}
};
To copy to clipboard, switch view to plain text mode
Bookmarks