QtCreator 用纯代码编写应用程序与命令行编译

来源:互联网 发布:linux脚本显示日期格式 编辑:程序博客网 时间:2024/06/10 21:27
  • 添加空程序
    • 添加C++ source file: main.cpp
    • #include <QApplication>
      #include <QDialog>
      #include <QLabel>
      int main(int argc, char** argv) {
          QApplication app(argc,argv);
          QDialog w;
          QLabel lbl(&w);
          lbl.setText("hello,你好!");
          w.show();
          return app.exec();
      }
  • 需要界面的QT程序都必须要在,*.pro文件里面加下面的语句
    • QT += core gui
    • greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
  • 避免中文出现乱码
  • #include <QApplication>
    #include <QDialog>
    #include <QLabel>
    #include <QTextCodec>
    int main(int argc, char** argv) {
        QApplication app(argc,argv);
        QTextCodec::setCodecForLocale(QTextCodec::codecForLocale());
        QDialog w;
        QLabel lbl(&w);
        lbl.setText(QObject::tr("你好!"));
        w.show();
        return app.exec();
    }

  • qmake -project
  • qmake
  • make
                                             
0 0