使用Console程序,非GUI應用寫了一個QLocalSocketServer,一開始運行就提示以下的問題:
QSocketNotifier: Can only be used with threads started with QThread事件
經分析知道,QSocket類須要一個事件循環來處理客戶接入,接收信息之類的,而我在main裏面爲了省事直接while(true);致使QSocket類沒法進入事件循環處理,這樣天然也沒辦法處理Client發過來的信息。it
解決辦法:io
在main裏面加入以下:thread
int main(int argc, char *argv[])sed
{循環
QApplication a(argc, argv);gc
// 你的程序程序
return a.exec();while
}return