Qt5.9 SDK 下載安裝_Qt Visual Studio插件安裝_搭配vs2015





Step1.至官網連結下載並安裝Qt
http://download.qt.io/archive/qt/5.9/5.9.0/



下載下來後進行安裝
















Step2.至官網連結下載並安裝Qt VS 插件
http://download.qt.io/archive/vsaddin/







在下載好的QT SDK路徑下
C:\Qt\Qt5.9.0\5.9\msvc2015\bin
C:\Qt\Qt5.9.0\5.9\msvc2015_64\bin
對應不同32或64的bin目錄下有動態連結檔案


要引入的頭文件路徑
C:\Qt\Qt5.9.0\5.9\msvc2015\include
C:\Qt\Qt5.9.0\5.9\msvc2015_64\include



library 路徑
C:\Qt\Qt5.9.0\5.9\msvc2015\lib
C:\Qt\Qt5.9.0\5.9\msvc2015_64\lib




於 Qt Creator 中生出一個專案



於本機定義好專案目錄
和一些常見之子目錄
bin
lib
src....





並確認路徑不要有任何中文

配置好專案預設路徑 下一步

由於Qt Creator可以一次同時建構出多個不同編譯環境之專案項

這裡使用 x64

將預設QMainWIndow類別換成 Qwidge
較簡單



一個UI設計檔案(.ui)
會對應一組 widge類(包含.cpp 及 .h)

版本控管設定  先跳至下一頁



專案成功建立


=================================================================


QT專案檔案結構分析



.pro檔案


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#-------------------------------------------------
#
# Project created by QtCreator 2018-06-21T00:42:07
#
#-------------------------------------------------

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = myQt
TEMPLATE = app

# The following define makes your compiler emit warnings if you use
# any feature of Qt which as been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS

# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0


SOURCES += \
        main.cpp \
        widget.cpp

HEADERS += \
        widget.h

FORMS += \
        widget.ui


頭檔案

widget.h Code :


#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>

namespace Ui {
class Widget;
}

class Widget : public QWidget
{
    Q_OBJECT

public:
    explicit Widget(QWidget *parent = 0);
    ~Widget();

private:
    Ui::Widget *ui;
};

#endif // WIDGET_H

具體去調用實作Qwidget Base Class的 檔案




widget.cpp Code


#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);
}

Widget::~Widget()
{
    delete ui;
}



程式進入點(入口檔案)
main.cpp




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

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    Widget w;
    w.show();

    return a.exec();
}


最後是所謂的介面設計器檔案
widge.ui
當你點兩下啟動它時預設
會開啟可視化拖拉的設計區

對應左側 鉛筆圖示的設計按鈕
QT 已將其轉為CPP 之視窗顯示樣子


對應左側 文件圖示的編輯按鈕
跑出區塊則是一段XML格式內容的檔案



在此我們嘗試去完成一個控件拖曳後
建置與執行時會出錯



錯誤訊息


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
19:10:10: 為專案 myQt 執行步驟...
19:10:10: 設置沒有改變,將跳過 qmake 步驟。
19:10:10: 正在啟動:"C:\Qt\Qt5.9.0\Tools\QtCreator\bin\jom.exe" 
 C:\Qt\Qt5.9.0\Tools\QtCreator\bin\jom.exe -f Makefile.Debug
 link /NOLOGO /DYNAMICBASE /NXCOMPAT /DEBUG /SUBSYSTEM:WINDOWS "/MANIFESTDEPENDENCY:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' publicKeyToken='6595b64144ccf1df' language='*' processorArchitecture='*'" /MANIFEST:embed /OUT:debug\myQt.exe @C:\Users\chous\AppData\Local\Temp\myQt.exe.11676.0.jom
LINK : fatal error LNK1158: cannot run 'rc.exe'
jom: D:\Qt_Project\src\build-myQt-Desktop_Qt_5_9_0_MSVC2015_64bit-Debug\Makefile.Debug [debug\myQt.exe] Error 1158
jom: D:\Qt_Project\src\build-myQt-Desktop_Qt_5_9_0_MSVC2015_64bit-Debug\Makefile [debug] Error 2
19:10:11: 行程 "C:\Qt\Qt5.9.0\Tools\QtCreator\bin\jom.exe" 已離開。離開代碼 2 。
Error while building/deploying project myQt (kit: Desktop Qt 5.9.0 MSVC2015 64bit)
The kit Desktop Qt 5.9.0 MSVC2015 64bit has configuration issues which might be the root cause for this problem.
When executing step "Make"
19:10:11: Elapsed time: 00:00.


LINK : fatal error LNK1158: cannot run 'rc.exe'

視主要錯誤原因
vs 找不到此執行檔案


解決方法1.
找到rc.exe的放置路徑
比如C:\Program Files (x86)\Windows Kits\10\bin\10.0.15063.0\x64

然后添加至系統環境變數的PATH中,重起Qt即可!

解決方法2.

把C:\Program Files (x86)\Windows Kits\10\bin\10.0.15063.0\x64 目錄下的
rc.exe 和rcdll.dll 給copy到



C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\amd64




這裡我使用  方法2.
成功解決




===========================================================

Visual Studio 2015 QT 專案新建
1.輸出、DEBUG、LIBRARY、HEADER設置
2.控制台開啟
3.修改引用的庫
4.修改解決方案的QT版本
5.輸出專給Qt Creator的專案檔案


配置好存放的專案程式碼路徑
D:\Qt_Project\src
並取好名稱
勾消 Create directory for solution的選項
避免多創建目錄














編譯運行時會出現的錯誤


https://www.leadwerks.com/community/topic/13486-visual-studio-community-2015-link-problem/

這邊比較怪異的點在於
我的電腦win10 x64上安裝了
vs2015 以及 vs2013兩個版本

這兩個版本
在設置上會有衝突
這裡雖然我是在vs2015上去進行 Qt 專案的新建羽編譯
將原來設置
Visual Studio 2015 (v140) 改為 Visual Studio 2013 (v120)




就可以修正bug錯誤











留言

這個網誌中的熱門文章

何謂淨重(Net Weight)、皮重(Tare Weight)與毛重(Gross Weight)

外貿Payment Term 付款條件(方式)常見的英文縮寫與定義

(2021年度)駕訓學科筆試準備題庫歸納分析_法規是非題