Created
April 24, 2019 12:45
-
-
Save lixingcong/d4e96d84cb3f8b5eb67dc863b4b65732 to your computer and use it in GitHub Desktop.
Q_INVOKABLE宏的简单用法
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <QObject> | |
#include <QDebug> | |
class MyClass : public QObject | |
{ | |
Q_OBJECT | |
public: | |
explicit MyClass(QObject *parent = nullptr):QObject(parent){} | |
Q_INVOKABLE void printHello(const QString& text) | |
{ | |
qDebug()<<"MyClass:"<<text; | |
} | |
}; | |
// ======== main.cpp =========== | |
int main(int argc, char *argv[]) | |
{ | |
QCoreApplication a(argc, argv); | |
auto myClass=new MyClass(&a); | |
QString str("main:"); | |
QMetaObject::invokeMethod(myClass, "printHello", Qt::QueuedConnection, Q_ARG(QString,str)); | |
return a.exec(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment