要注意末尾的 #include "main.moc"
#include <QCoreApplication>
#include <QDebug>
class F: public QObject
{
Q_OBJECT
public:
void myslot(int para)
{
qDebug()<<"my slot:"<<para<<endl;
}
static void myslot2(int para)
{
qDebug()<<"my slot2:"<<para<<endl;
}
signals:
void mysig(int);
};
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
F *aaa = new F();
QObject::connect(aaa, &F::mysig, aaa, &F::myslot);
QObject::connect(aaa, &F::mysig, [](int x){
qDebug()<<"my lamda:"<< x << endl;
});
QObject::connect(aaa, &F::mysig, &F::myslot2);
emit aaa->mysig(3);
return a.exec();
}
#include "main.moc"