PDA

View Full Version : QMetaObject::invokeMethod: Unable to handle unregistered datatype 'quit16'



vratojr
22nd February 2006, 17:28
Hello, I had a working program with Qt 4.0.1. I have upgraded to Qt 4.1.0 and now I got the error in the title when I try to use the connectToHost() command.
I'm using kdevelop 3.2, I have erased the old Makefiles and ran qmake.
I have also set the new PATH in my bash.profile.

Any hint?

Thanks

jacek
22nd February 2006, 18:20
Try:
qRegisterMetaType<quint16>("quint16");

vratojr
23rd February 2006, 10:31
Try:
qRegisterMetaType<quint16>("quint16");

I tryed but then I got the same message but with 'OpenMode' unregistered...:(

jacek
23rd February 2006, 10:39
I tryed but then I got the same message but with 'OpenMode' unregistered...:(
Are you sure that your program worked with Qt 4.0.1? Maybe it was 4.0.0?

In Qt 4.0.1 there was a slight change in SLOT and SIGNAL macros:
Qt 4.0.0 introduced a change to the way type names outside the current
scope were handled in signals and slots declarations and connections
which differed from the behavior in Qt 3.x.

Unfortunately, this could lead to signal-slot connections that were
potentially type-unsafe. Therefore, in Qt 4.0.1 type names must be fully
qualified in signal-slot declarations and connections.

For example, in Qt 4.0.0, it was possible to write:

connect(socket, SIGNAL(error(SocketError)), ...);

In Qt 4.0.1, the above connection must be made in the following way:

connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), ...);

vratojr
23rd February 2006, 10:50
Are you sure that your program worked with Qt 4.0.1? Maybe it was 4.0.0?

In Qt 4.0.1 there was a slight change in SLOT and SIGNAL macros:

Yes,I'm sure. The directory I use is called Qt 4.0.1 and I use the syntax that you wrote above. Moreover, the problem that I get doesn't come from a "connect" macro.

jacek
23rd February 2006, 10:59
Could you post the line where you invoke that connectToHost() method? Do you use threads?

vratojr
23rd February 2006, 11:13
Could you post the line where you invoke that connectToHost() method? Do you use threads?

Yes:

serverSocket->connectToHost("5.244.185.198",1111);

I call it in the run() function of a thread.

jacek
23rd February 2006, 11:15
I call it in the run() function of a thread.
Where do you create the object that serverSocket points to?

vratojr
23rd February 2006, 11:23
The structure of the program is:

Socket is a sublcass of tcpsocket,I symply rewrote the write and read methods.

class UserThread : public QThread{
....
private:
Socket *serverSocket;
...
}

In the constructor I call:

serverSocket = new Socket();

then, in run I call the connectToHost().

jacek
23rd February 2006, 11:27
In the constructor I call:

serverSocket = new Socket();

then, in run I call the connectToHost().
So the problem is that your serverSocket was created in a different thread (the one that created the thread object). You should instantiate this socket in the run() method.

vratojr
23rd February 2006, 11:36
So the problem is that your serverSocket was created in a different thread (the one that created the thread object). You should instantiate this socket in the run() method.

But, I read that the problem arises when the socket is son of a different thread,no? If I call

serverSocket = new Socket()
in the constructor of my thread and don't pass "this" to the constructor of the socket, doens't the socket be a "stand_alone" object?
Afterward i call

delete serverSocket
in the destructor of the thread.

And why this doesn't work with qt 4.1.0 but instead it works with 4.1.0?

jacek
23rd February 2006, 11:42
in the constructor of my thread and don't pass "this" to the constructor of the socket, doens't the socket be a "stand_alone" object?
But still it will be living in a different thread.


Afterward i call delete serverSocket in the destructor of the thread.
You could use QObject::deleteLater() (if it's possible) or delete in just before run() returns.

There is also QObject::moveToThread().


And why this doesn't work with qt 4.1.0 but instead it works with 4.1.0?
I don't know, but you should get a lot of warnings on the console.

vratojr
23rd February 2006, 11:54
Thank you very much!
I created the socket in the run() method and now all works good.

KShots
7th February 2007, 22:53
I'm suffering from this same problem, and I have a single-threaded application.

I invoke QTcpSocket in a separate class as a static object with no parent (attempting to set a parent after it has been instantiated seems to confuse QObject and create free() errors on shutdown). An entirely different class then takes this socket and tries to make it connect to a remote server.

Here's what the connection looks like:
QTcpSocket * mySocket = &formBasePlugin::socketServer;
mySocket->connectToHost(ui.lineEditHost->text(), ui.spinBoxPort->value(), QIODevice::ReadWrite);

jacek
7th February 2007, 23:05
a static object with no parent

http://www.trolltech.com/developer/task-tracker/index_html?method=entry&id=90881


attempting to set a parent after it has been instantiated seems to confuse QObject and create free() errors on shutdown
Every QObject that has a parent will be deleted when it's parent gets destroyed, but on the other hand you can't delete static objects. So either make that object non-static or reparent it again.

KShots
8th February 2007, 01:39
Ah, I think I see the problem, then. Although they fixed the bug you mention in 4.2.0, I am using 4.1.4 (latest version available that plays nice with dbus). So... I'll see if I can find a way to make this thing work without a static socket. Thanks!

jacek
8th February 2007, 01:42
I'll see if I can find a way to make this thing work without a static socket.
Maybe QObject::moveToThread() will be enough?

KShots
8th February 2007, 16:30
That worked - the socket is still static, but it is now functional :).

Thanks!