#include <QApplication>#include <QPushButton>#include <QWidget>#include <QGridLayout>class MyClass : public QObject { Q_OBJECT public: MyClass(); public slots: void MyFunc();};MyClass::MyClass() {}void MyClass::MyFunc() { printf ( "asdffffffffdasf\n" ); }int main( int argc, char *argv[] ) { QApplication app( argc, argv ); QWidget *window = new QWidget; window->resize( 500, 500 ); QPushButton *button1 = new QPushButton( "One" ); QObject::connect( button1, SIGNAL( clicked() ), &app, SLOT( quit() ) ); MyClass *myClass = new MyClass(); QPushButton *button2 = new QPushButton( "Two" ); QObject::connect( button2, SIGNAL( clicked() ), &app, SLOT( myClass->MyFunc() ) ); /* вот тут проблема */ QGridLayout *layout = new QGridLayout; layout->addWidget( button1, 0, 0 ); layout->addWidget( button2, 0, 1 ); window->setLayout( layout ); window->show(); return app.exec();}
QObject::connect( button2, SIGNAL( clicked() ), &myClass, SLOT( MyFunc() ) );
C++ (Qt)#include "main.moc"
C++ (Qt)make distclean && qmake && make