#:~/projects/Qt4/server> ./server
new connection id: 8
Worker running
QNativeSocketEngine::
received data
going to create response!
send answer
flushed socket
################## ! ! ! ! #####################
QObject: Cannot create children
for a parent that is in a different thread.
#^#^#^#^############## ! ! ! ! #################
new connection id: 12
Worker running
QNativeSocketEngine::
received data
going to create response!
send answer
flushed socket
################## ! ! ! ! #####################
QObject: Cannot create children
for a parent that is in a different thread.
#^#^#^#^############## ! ! ! ! #################
received data
going to create response!
send answer
flushed socket
#:~/projects/Qt4/server> ./server
new connection id: 8
Worker running
QTcpSocket::
QNativeSocketEngine::
QSocketNotifier::
received data
going to create response!
send answer
flushed socket
################## ! ! ! ! #####################
QObject: Cannot create children for a parent that is in a different thread.
QSocketNotifier: socket notifiers cannot be disabled from another thread
#^#^#^#^############## ! ! ! ! #################
new connection id: 12
Worker running
QTcpSocket::
QNativeSocketEngine::
QSocketNotifier::
received data
going to create response!
send answer
flushed socket
################## ! ! ! ! #####################
QObject: Cannot create children for a parent that is in a different thread.
QSocketNotifier: socket notifiers cannot be disabled from another thread
#^#^#^#^############## ! ! ! ! #################
received data
going to create response!
send answer
flushed socket
To copy to clipboard, switch view to plain text mode
gdb - output
Breakpoint
2,
QObject (this=0x8059260, parent
=0x8056ca8
) at qobject.
cpp:619619 qWarning("QObject: Cannot create children for a parent that is in a different thread.");
(gdb) backtrace
#0 QObject (this=0x8059260, parent=0x8056ca8) at qobject.cpp:619
#1 0x4022ffaa in QSocketNotifier (this=0x8059260, socket=12, type=Write, parent=0x8056ca8) at qsocketnotifier.cpp:124
#2 0x400978e3 in QNativeSocketEngine::setWriteNotificationEnabled (this=0x8056ca8, enable=true)
at qnativesocketengine.cpp:915
#3 0x400a5681 in QAbstractSocket::writeData (this=0x8058f08, data=0x805a3e0 "Server reseived: soso\r\n\n", size=24)
at qabstractsocket.cpp:1761
#4 0x401ae99b in QIODevice::write (this=0x8058f08, data=0x805a3e0 "Server reseived: soso\r\n\n", maxSize=24)
at qiodevice.cpp:1241
#5 0x40081969 in QIODevice::write (this=0x8058f08, data=@0xbfffe950) at qiodevice.h:105
#6 0x401b5438 in QTextStreamPrivate::flushWriteBuffer (this=0x8059298) at qtextstream.cpp:617
#7 0x401b66c1 in ~QTextStream (this=0xbfffe9c0) at qtextstream.cpp:1019
#8 0x0804b115 in Worker::respond (this=0x8057ce8) at worker.cpp:82
#9 0x0804ae92 in Worker::bufferData (this=0x8057ce8) at worker.cpp:59
#10 0x0804b384 in Worker::qt_metacall (this=0x8057ce8, _c=InvokeMetaMethod, _id=0, _a=0x805a430) at moc_worker.cpp:66
#11 0x40223e57 in QObject::event (this=0x8057ce8, e=0x805a1d8) at qobject.cpp:1022
#12 0x40210a72 in QCoreApplicationPrivate::notify_helper (this=0x804e130, receiver=0x8057ce8, event=0x805a1d8)
at qcoreapplication.cpp:613
#13 0x40210881 in QCoreApplication::notify (this=0xbfffef30, receiver=0x8057ce8, event=0x805a1d8)
at qcoreapplication.cpp:571
#14 0x402148cb in QCoreApplication::sendEvent (receiver=0x8057ce8, event=0x805a1d8) at qcoreapplication.h:183
#15 0x402114e6 in QCoreApplication::sendPostedEvents (receiver=0x0, event_type=0) at qcoreapplication.cpp:1022
#16 0x4023e1f5 in postEventSourceDispatch (s=0x8056968) at qeventdispatcher_glib.cpp:250
#17 0x4050ffc7 in g_main_context_dispatch () from /opt/gnome/lib/libglib-2.0.so.0
#18 0x40512392 in g_main_context_acquire () from /opt/gnome/lib/libglib-2.0.so.0
#19 0x405124a3 in g_main_context_iteration () from /opt/gnome/lib/libglib-2.0.so.0
#20 0x4023f183 in QEventDispatcherGlib::processEvents (this=0x8055800, flags={i = 20}) at qeventdispatcher_glib.cpp:363
---Type <return> to continue, or q <return> to quit---
#21 0x4020df81 in QEventLoop::processEvents (this=0xbfffeed0, flags={i = 20}) at qeventloop.cpp:125
#22 0x4020e06d in QEventLoop::exec (this=0xbfffeed0, flags={i = 0}) at qeventloop.cpp:171
#23 0x40210cda in QCoreApplication::exec () at qcoreapplication.cpp:720
#24 0x08049f85 in main (argc=1, argv=0xbfffefd4) at main.cpp:11
gdb - output
Breakpoint 2, QObject (this=0x8059260, parent=0x8056ca8) at qobject.cpp:619
619 qWarning("QObject: Cannot create children for a parent that is in a different thread.");
(gdb) backtrace
#0 QObject (this=0x8059260, parent=0x8056ca8) at qobject.cpp:619
#1 0x4022ffaa in QSocketNotifier (this=0x8059260, socket=12, type=Write, parent=0x8056ca8) at qsocketnotifier.cpp:124
#2 0x400978e3 in QNativeSocketEngine::setWriteNotificationEnabled (this=0x8056ca8, enable=true)
at qnativesocketengine.cpp:915
#3 0x400a5681 in QAbstractSocket::writeData (this=0x8058f08, data=0x805a3e0 "Server reseived: soso\r\n\n", size=24)
at qabstractsocket.cpp:1761
#4 0x401ae99b in QIODevice::write (this=0x8058f08, data=0x805a3e0 "Server reseived: soso\r\n\n", maxSize=24)
at qiodevice.cpp:1241
#5 0x40081969 in QIODevice::write (this=0x8058f08, data=@0xbfffe950) at qiodevice.h:105
#6 0x401b5438 in QTextStreamPrivate::flushWriteBuffer (this=0x8059298) at qtextstream.cpp:617
#7 0x401b66c1 in ~QTextStream (this=0xbfffe9c0) at qtextstream.cpp:1019
#8 0x0804b115 in Worker::respond (this=0x8057ce8) at worker.cpp:82
#9 0x0804ae92 in Worker::bufferData (this=0x8057ce8) at worker.cpp:59
#10 0x0804b384 in Worker::qt_metacall (this=0x8057ce8, _c=InvokeMetaMethod, _id=0, _a=0x805a430) at moc_worker.cpp:66
#11 0x40223e57 in QObject::event (this=0x8057ce8, e=0x805a1d8) at qobject.cpp:1022
#12 0x40210a72 in QCoreApplicationPrivate::notify_helper (this=0x804e130, receiver=0x8057ce8, event=0x805a1d8)
at qcoreapplication.cpp:613
#13 0x40210881 in QCoreApplication::notify (this=0xbfffef30, receiver=0x8057ce8, event=0x805a1d8)
at qcoreapplication.cpp:571
#14 0x402148cb in QCoreApplication::sendEvent (receiver=0x8057ce8, event=0x805a1d8) at qcoreapplication.h:183
#15 0x402114e6 in QCoreApplication::sendPostedEvents (receiver=0x0, event_type=0) at qcoreapplication.cpp:1022
#16 0x4023e1f5 in postEventSourceDispatch (s=0x8056968) at qeventdispatcher_glib.cpp:250
#17 0x4050ffc7 in g_main_context_dispatch () from /opt/gnome/lib/libglib-2.0.so.0
#18 0x40512392 in g_main_context_acquire () from /opt/gnome/lib/libglib-2.0.so.0
#19 0x405124a3 in g_main_context_iteration () from /opt/gnome/lib/libglib-2.0.so.0
#20 0x4023f183 in QEventDispatcherGlib::processEvents (this=0x8055800, flags={i = 20}) at qeventdispatcher_glib.cpp:363
---Type <return> to continue, or q <return> to quit---
#21 0x4020df81 in QEventLoop::processEvents (this=0xbfffeed0, flags={i = 20}) at qeventloop.cpp:125
#22 0x4020e06d in QEventLoop::exec (this=0xbfffeed0, flags={i = 0}) at qeventloop.cpp:171
#23 0x40210cda in QCoreApplication::exec () at qcoreapplication.cpp:720
#24 0x08049f85 in main (argc=1, argv=0xbfffefd4) at main.cpp:11
To copy to clipboard, switch view to plain text mode
void Server::incomingConnection(int socketId){
qDebug() << "new connection id: " << socketId;
Worker *wrk = new Worker(this, socketId);
}
void Worker::run(){
qDebug() << "Worker running";
// _socket = new QTcpSocket(currentThread()); // Fails with
// "Cannot create children for a parent that is in a different thread." --- Why??
_socket->setSocketDescriptor(_socketDescriptor);
_socket->dumpObjectTree();
connect(_socket, SIGNAL(readyRead()), this, SLOT(bufferData()));
forever{
}
}
void Worker::respond(){
qDebug() << "going to create response!";
QByteArray response
= dad
->getResourceInstance
()->createResponse
(buffer
);
dad->releaseResourceInstance();
os << response << "\n";
qDebug() << "send answer";
_socket->flush();
qDebug() << "flushed socket";
}
void Server::incomingConnection(int socketId){
qDebug() << "new connection id: " << socketId;
Worker *wrk = new Worker(this, socketId);
((QThread*)wrk)->start();
}
void Worker::run(){
qDebug() << "Worker running";
_socket = new QTcpSocket();
// _socket = new QTcpSocket(currentThread()); // Fails with
// "Cannot create children for a parent that is in a different thread." --- Why??
_socket->setSocketDescriptor(_socketDescriptor);
_socket->dumpObjectTree();
connect(_socket, SIGNAL(stateChanged(QAbstractSocket::SocketState)), this, SLOT(socketStateChanged(QAbstractSocket::SocketState)));
connect(_socket, SIGNAL(readyRead()), this, SLOT(bufferData()));
forever{
QCoreApplication::processEvents(QEventLoop::WaitForMoreEvents);
}
}
void Worker::respond(){
qDebug() << "going to create response!";
QByteArray response = dad->getResourceInstance()->createResponse(buffer);
dad->releaseResourceInstance();
QTextStream os(_socket);
os << response << "\n";
qDebug() << "send answer";
_socket->flush();
qDebug() << "flushed socket";
}
To copy to clipboard, switch view to plain text mode
Bookmarks