QT写hello world 以及信号槽机制

QT是一个C++的库,不仅仅有GUI的库。首先写一个hello world吧。敲代码,从hello world 写起。

 1 #include<QtGui/QApplication> 2 #include<QLabel> 3  4 int main(int argc , char *argv[]) 5 { 6    QApplication app (argc , argv); 7    QLabel *lebal = new QLabel (" hello world!"); 8    lebal->show();  9    return app.exec();10 }

这里插一句啊 QT是可以接受HTML解析的。

QT中,QApplication app ( argc.argv);

….

return app.exec();语句是必备的。

QT的信号槽机制:

先写下代码

 1 #include<QtGui/QApplication>      2 #include<QtGui/QPushButton> 3  4 int main( int agrc , char *agrv[]) 5 { 6   QApplication a ( agrc, agrv); 7   QPushButton* button = new QPushButton(“Quit”); 8   QObject::connect( button ,SIGNAL(clicked()) , &a , SLOT(quit())); 9   button->show();10   return a.exec();11 }

信号槽就是将一个clicked信号与槽函数绑定,上述代码就是,把quit这个按钮,在点击之后,发送一个clicked信号,如果这个槽正好对应这个信号,那就执行这个槽函数,也就是quit()函数,也就是回调。

QObject 是所有根的类,它的里面有一个connect静态函数,用来连接信号槽。QT用信号槽来监听事件消息。

对的,坚持;错的,放弃!

QT写hello world 以及信号槽机制

相关文章:

你感兴趣的文章:

标签云: