PHP interesse |
|
Ik heb een probleempje met een Qt dinges... ik ben net met Qt begonnen en ik weet nog neit precies hoe het signal/slots systeem werkt, maar dit werkt iig niet. klikken op de changetext knop geeft geen reactie =/ Wat moet ik doen?
#include <qapplication.h>
#include <qpushbutton.h>
#include <qfont.h>
#include <qlabel.h>
#include <qmessagebox.h>
class MyWidget : public QWidget
{
public:
MyWidget( QWidget *parent=0, const char *name=0 );
private:
QLabel * status;
public slots:
void updatetext();
};
MyWidget::MyWidget( QWidget *parent, const char *name )
: QWidget( parent, name )
{
setMinimumSize( 200, 200 );
setMaximumSize( 200, 200 );
QPushButton *quit = new QPushButton( "Quit", this, "quit" );
quit->setGeometry( 0, 0, 75, 30 );
QPushButton *changetext = new QPushButton( "Change Text", this, "changetext" );
changetext->setGeometry( 100, 100, 75, 30 );
QLabel *status = new QLabel("Status Label", this, "status");
status->setGeometry( 0, 100, 75, 30 );
connect( changetext, SIGNAL(clicked()), qApp, SLOT(updatetext()) );
connect( quit, SIGNAL(clicked()), qApp, SLOT(quit()) );
}
void MyWidget::updatetext()
{
QMessageBox::information(this, "Notification", "Function initiated");
status->setText("Done");
}
int main( int argc, char **argv )
{
QApplication a( argc, argv );
MyWidget w;
w.setGeometry( 300, 300, 300, 300);
a.setMainWidget( &w );
w.show();
return a.exec();
}
#include <qapplication.h> #include <qpushbutton.h> #include <qfont.h> #include <qlabel.h> #include <qmessagebox.h> class MyWidget : public QWidget { public: MyWidget( QWidget *parent=0, const char *name=0 ); private: QLabel * status; public slots: void updatetext(); }; MyWidget::MyWidget( QWidget *parent, const char *name ) : QWidget( parent, name ) { setMinimumSize( 200, 200 ); setMaximumSize( 200, 200 ); QPushButton *quit = new QPushButton( "Quit", this, "quit" ); quit->setGeometry( 0, 0, 75, 30 ); QPushButton *changetext = new QPushButton( "Change Text", this, "changetext" ); changetext->setGeometry( 100, 100, 75, 30 ); QLabel *status = new QLabel("Status Label", this, "status"); status->setGeometry( 0, 100, 75, 30 ); connect( changetext, SIGNAL(clicked()), qApp, SLOT(updatetext()) ); connect( quit, SIGNAL(clicked()), qApp, SLOT(quit()) ); } void MyWidget::updatetext() { QMessageBox::information(this, "Notification", "Function initiated"); status->setText("Done"); } int main( int argc, char **argv ) { QApplication a( argc, argv ); MyWidget w; w.setGeometry( 300, 300, 300, 300); a.setMainWidget( &w ); w.show(); }
|