zoukankan      html  css  js  c++  java
  • 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用信号槽来监听事件消息。

  • 相关阅读:
    没事千万不要升级VirtualBox和Vagrant!
    以太坊开源项目
    以太坊合约第三方库
    Redis dbfilename
    SUSE Redis 开机启动
    SUSE Linux Enterprise Server 12 SP3 安装redis 6.0以上版本
    HTML基础练习
    html基础
    关于css 浮动的例子
    css 实现三角形
  • 原文地址:https://www.cnblogs.com/132818Creator/p/7117405.html
Copyright © 2011-2022 走看看