本人使用的是Qt5.7版本的,请读者自主下载安装。

 

今天首先来进行Qt入门的第一个程序,也是很经典的一个例子。这是在很多的变成语言中都会用到的例子,就是输出helloworld这个信息。Qt中使用的变成语言是C++语言,如果读者对C++这变成语言不太熟悉的话,可以自行查看相应的C++学习教程,这里不多收。

具体的步骤:

  1. 创建Qt项目
  2. Qt之hello world
  3. Qt之hello world
  4. Qt之hello world
  5. Qt之hello world
  6. Qt之hello world
  7. 在main.cpp中编写输出的内容
  8. #include "helloworld.h"
    #include <QApplication>
    
    #include <QDebug>  //添加这个头文件,用来输出信息
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
    //    helloworld w;  //注释下面两条语句,我们直接在main中进行输出helloworld
    //    w.show();
    
        qDebug()<<"hello world";
    
        return a.exec();
    }

      Qt之hello world

 

当然上述的例子只是一个简单的例子,很多人都会,因为在C语言或者C++中都在main函数中进行这个helloworld的输出,但是,现在采用一种Qt的C++方法进行输出。

请看例子:

   在项目的helloworl.cpp的构造函数中,添加以下代码

  

#include "helloworld.h"

#include <QDebug>  //添加这个头文件,用来输出信息

helloworld::helloworld(QWidget *parent)
    : QMainWindow(parent)
{
    qDebug() << "hello world";
}

helloworld::~helloworld()
{

}

  同时修改main.cpp中的main函数的内容,

#include "helloworld.h"
#include <QApplication>



int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    helloworld w;
    //w.show();  /*注释这个话,不然的话,就会出现弹幕*/


    return a.exec();
}

  

同样输出的结果如下:

Qt之hello world

 

相关文章:

  • 2022-01-10
  • 2021-05-10
  • 2021-04-19
  • 2021-08-16
  • 2021-12-19
  • 2021-12-31
  • 2019-09-01
  • 2021-11-16
猜你喜欢
  • 2021-07-28
  • 2021-04-24
  • 2022-01-23
  • 2022-12-23
  • 2021-09-20
  • 2021-04-24
  • 2022-12-23
相关资源
相似解决方案