Details
-
Bug
-
Resolution: Done
-
P2: Important
-
4.6.2, 4.8.0
-
None
-
49a5cf7cd44584e04d1f54f3fbd0d5c86fe55c83
Description
According to the QtCore module code QMetaMethod::invoke() doesn't checks that method user wants to invoke exists in the QObject given as parameter. Attached archive contains simple example how to reproduce this bug.
There are two classess A and B both derived from QObject. Class A has slot foo() and class B has slot bar(). I'm invoking foo() and bar() using QMetaMethod::invoke() passing pointer to instance of class A and instance of class B. In every case invoke calls some function and returns true even if parameter is incorrect.
Since QMetaMethod contains pointer to QMetaObject instance it should be possible to check if this method is member of the object given before invocation.
I suppose but unsure that it can be done with the following code:
---------
QMetaObject meta = object.metaObject();
bool isMember = false;
while ( meta ) {
if ( meta == this->mobj )
meta = meta->superClass();
}
---------
This code may not work if it's possible that there can be a class with two or more corresponding QMetaObject instances. As far as I can understand the code generated by moc such situation should be impossible. The only uncertain place for me is if there is a class in some static library and there are two shared libraries linked with this static library. How many meta object instances for this class will be available in an application linked with both shared libraries? I think answer on this question may depend on compiler and operation system.
Here is output obtained by running attached example:
----------
Correct invocation: A::foo()
A::foo
Correct invocation: B::bar()
B::bar
Incorrect invocation: B::foo()
B::bar
Incorrect invocation: A::bar()
A::foo
----------
The same output obtained when using 4.6.2 and HEAD of master branch.