[Qt-interest] "indexOfMethod" always return -1 if it's parameter is not a slot or sigal, why
Yao Huiji
spideryao at gmail.com
Tue Aug 18 04:21:26 CEST 2009
sorry , I press the send shortcut key unguardedly.
here is my code:
############### tictac.h ######################
#ifndef TICTAC_H
#define TICTAC_H
#include <QObject>
class QTimerEvent;
class QString;
class TicTac : public QObject
{
Q_OBJECT
public:
TicTac();
//public slots:
void SayHi();
protected:
void timerEvent(QTimerEvent *event);
};
#endif // TICTAC_H
##################################
############# main.cpp #####################
#include <QtCore/QCoreApplication>
#include "tictac.h"
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
TicTac *tictac = new TicTac;
const QMetaObject *meta = tictac->metaObject();
QString str;
if(meta->indexOfMethod("SayHi()") != -1)
{
meta->invokeMethod(tictac,"SayHi",Qt::DirectConnection);
}
else
{
qDebug("No such method!");
}
qDebug(str.toStdString().c_str());
return a.exec();
}
##################################
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090818/e7a1b3be/attachment.html
More information about the Qt-interest-old
mailing list