Solved Differences from two connect declaration
-
Hi
I'm novice in QT world, and I found a very strange problem (for me) about connect declaration. I've created SIGNAL and SLOT custom in my class, and if I use:connect(socket, SIGNAL(disconnectedCustom()), this, SLOT(myDisconnection()));
When code run my program crash and in debug I see:
c:\users\qt\work\qt\qtbase\src\corelib\tools\qscopedpointer.h:140: error: Debugger encountered an exception: Exception at 0x7ffef8222d4a, code: 0xc0000005: read access violation at: 0xffffffffffffffff, flags=0x0 (first chance)
But, if remove previous line and I write:
connect(socket,&mySocket::disconnectedCustom, this, &MyTcpServer::myDisconnection);
It works fine (socket is an instance of mySocket, and this is MyTcpServer). socket is created with new:
mySocket *socket = new mySocket(server->nextPendingConnection()); // serve is QTcpServer instance.
I thought (wrongly) that the two previous lines did the same thing, but obviously I'm wrong. Can someone explain to me what is wrong with the first line?
Thanks (and sorry for my bad english).
-
Hi and welcome to devnet forum
There should be no difference performance- or stability-wise with the different version of connect you have tried.
The first version is the older macro based version, which will tell you only during prcoessing that there might be problem (e.g. signal or slot missing). However, it should not cause a crash.The second form is newer and hasthe advantage of giving a compile error when something in the declaration or elsewhere is wrong. Personally I see the benefit there because you do not have to wait until the signal is issued, because the warnings with the older version are often hidden by additional output and therefore not seen.
Most likely there some sort of change in source not properly compiled and linked, which caused the crash. If you are interested you may want to change back to macro based version for sanity check.
-
Hi koahnig, thanks for the reply. I refactored all my code (after more test and code) and now I use new method to connect signal and slot. Now it works fine - I think the previous problem was due to my inexperience.
-
You are welcome.
We all have to start somewhere in the beginning not everything is logic until the pieces of the puzzle falling into place.
Enjoy programming with Qt