#include <QCoreApplication>
#include <QDebug>
#include <QObject>
#include <the QThread>
#include <String>
#include <the iostream>
#include "mythread.h"
the using namespace STD;
// Qt console application window directly in exit method.
main int (int argc, char * the argv [])
{
QString STR;
the QTextStream OUT (stdout);
OUT << "INPUT Data" << endl;
the QTextStream in (stdin);
in STR >>;
OUT << "INPUT STR = "<< endl << str;
QCoreApplication A (argc, argv);
MyThread * = MyThread new new MyThread ();
// exit the second method by calling quit in the child thread inside (), quit the whole program
QObject :: connect (mythread , SIGNAL (finished ()), & a, SLOT (quit ()));
// exit these failures?
//a.quit ();
//a.exit(0);
// QCoreApplication :: Exit (0);
// QCoreApplication :: quit ();
qDebug () << "Test quit" << endl;
/ / exit (0); // exiting method a
return a.exec ();
// return 0;
}
#ifndef MYTHREAD_H
#define MYTHREAD_H
#include <QObject>
#include <QThread>
class MyThread : public QThread
{
Q_OBJECT
public:
explicit MyThread(QObject *parent = 0);
protected:
void run();
};
#endif // MYTHREAD_H
#include "mythread.h"
#include <string>
#include <iostream>
using namespace std;
MyThread::MyThread(QObject *parent):QThread(parent)
{
}
void MyThread::run()
{
char *pszTip = "Press 'Q' exit application.\n";
printf("%s\n", pszTip);
/*
while (true)
{
std::string line;
std::cin>>line;
std::cout<<line<<std::endl;
printf("%s", pszTip);
if (line.compare("Q")==0)
{
break;
}
}
*/
printf("Done.");Source: CSDNAuthor: yunshouhu---------------------
}
Original: https: //blog.csdn.net/earbao/article/details/53771496
Copyright: This article is a blogger original article, reproduced, please attach Bowen link!