0
我有一個(有點)簡單的程序創建新線程,每個連接到插座一個:創建的QObject:findChildren和QThread的
void TelnetServer::incomingConnection(qintptr socketDescriptor)
{
TelnetConnection *thread = new TelnetConnection(socketDescriptor);
connect(thread, SIGNAL(shutdownRequested()), m_controller, SLOT(shutdown()));
connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
thread->start();
}
一個新的線程後,我輸出到qDebug所有列表創建該QThreads(TelnetConnection的)家長像這樣的孩子:
QList<QObject*> activeTelnetConnections = m_telnetserver->findChildren <QObject *>(); // Find all QThreads that children of telnetserver
qDebug() << "Children: " << activeTelnetConnections;
由於我QThreads自QObject decend,我希望看到QThreads多的列表。但是,我找不到Q線程!這是我看到的:
Children: (QNativeSocketEngine(0x7eb880) , QSocketNotifier(0x7ea5f0))
爲什麼我看不到子線程?這是否意味着線程不再與父對象關聯?或者我在這裏做錯了什麼...
就是這樣 - 我必須在構造函數的初始化行上設置父級,然後纔可見! – TSG