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

 
  
  • 添加空程序
    • 添加C++ source file: main.cpp
    • #include 
      #include 
      #include 
      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 
    #include 
    #include 
    #include 
    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
 
  
 
  
 
  
 
  
 
 

你可能感兴趣的:(Qt,C++)