Reputation: 127
I try to build a Multi Threading Game Server used QT,so, every client is a standalone thread based "QThread".now I need to send data to other clients(in other thread) whichs in the same game room. example,When a house-owner closed the game room, the Game Server needs to send to the "room_closed" message to other clients whichs in the same soom, but there is an error :
QSocketNotifier: Socket notifiers cannot be enabled or disabled from another thread
ps: I tryed to use the sinals/slots but there is still a error:
QObject: Cannot create children for a parent that is in a different thread. (Parent is QNativeSocketEngine(0x161764e8), parent's thread is ClientThread(0x16196f10), current thread is QThread(0x14a17278)
what should I do?
Upvotes: 2
Views: 8107
Reputation: 1
You called QTcpSocket::write in multiple therads. I solved the problem with signal/slot.
Upvotes: -1
Reputation: 8311
It seems you do not handle QObjects and QThreads properly and Qt complains about it.
I suggest you take a look at Qt documentation:
A quick guide:
QObject::thread()
).QObject::moveTothread()
, but the QObject must not have a parent and the call must be made from the thread the QObject is currently associated with.Upvotes: 3