PDA

View Full Version : How to use QMetaObject::invokeMethod?



niko
26th January 2008, 14:42
my testcase:


class test : public QObject
{
Q_OBJECT
public slots:
void foo() {
qDebug() << "foo called";
}
};

int main(int argc, char** argv)
{
QApplication app(argc,argv);
test* x = new test;
x->foo(); //works
QTimer::singleShot(0, x, SLOT(foo())); //works
QMetaObject::invokeMethod(x, SLOT(foo())); //doesn't work
app.exec();
}
#include "main.moc"


what's wrong? Why doesn't this work? (invoceMethod returns false - which means that the method is not found)

thanks,
niko

jpn
26th January 2008, 15:44
QMetaObject::invokeMethod(x, "foo");

wysota
26th January 2008, 15:50
Try without the SLOT() macro.

niko
26th January 2008, 16:02
of course - it all is written in the docs :D