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