Qt 与 WinRT C++ 构建问题
Qt with WinRT C++ build issue
我想使用 WinRT
(Windows 10) 构建现代 Windows 应用程序。我为 Visual Studio 2017
使用 Qt 5.13.1 UWP
套件。建工程时,显示编译错误很多:
代码:
testproject.pro
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
CONFIG += c++17
# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked 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 it uses 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 \
testproject.cpp
HEADERS += \
testproject.h
FORMS += \
testproject.ui
LIBS += -lwindowsapp
# Default rules for deployment.
#qnx: target.path = /tmp/$${TARGET}/bin
#else: unix:!android: target.path = /opt/$${TARGET}/bin
#!isEmpty(target.path): INSTALLS += target
testproject.h
#ifndef TESTPROJECT_H
#define TESTPROJECT_H
#include <QDialog>
#include <QDebug>
#include "winrt/Windows.System.Diagnostics.h"
using namespace winrt;
using namespace Windows::System::Diagnostics;
QT_BEGIN_NAMESPACE
namespace Ui { class TestProject; }
QT_END_NAMESPACE
class TestProject : public QDialog
{
Q_OBJECT
public:
TestProject(QWidget *parent = nullptr);
~TestProject();
private:
Ui::TestProject *ui;
};
#endif // TESTPROJECT_H
testproject.cpp
#include "testproject.h"
#include "ui_testproject.h"
TestProject::TestProject(QWidget *parent)
: QDialog(parent)
, ui(new Ui::TestProject)
{
ui->setupUi(this);
init_apartment();
auto info = SystemDiagnosticInfo::GetForCurrentSystem();
auto memory = info.MemoryUsage().GetReport().TotalPhysicalSizeInBytes();
qDebug() << memory;
}
TestProject::~TestProject()
{
delete ui;
}
没有WinRT
代码编译成功。关于如何使用 Qt
配置 WinRT
有什么想法吗? Qt
到 运行 WinRT
代码需要哪些库?提前致谢。
尝试在 #include "winrt/Windows.System.Diagnostics.h"
之前添加 #undef X64
或转到您的项目设置,select "Configuration Properties" -> "C/C++" -> "Preprocessor",在 "Preprocessor Definitions" select "Edit"[=21= 旁边的下拉列表中], 删除行 X64
。我不知道这个定义是做什么用的,但它与 Windows.System.0.h.
中的 ProcessorArchitecture::X64
枚举冲突
PS。这个答案只是一个复制的猜测,因为我无法理解屏幕截图上的错误。通常从输出面板复制粘贴文本比错误列表提供更多信息。
我想使用 WinRT
(Windows 10) 构建现代 Windows 应用程序。我为 Visual Studio 2017
使用 Qt 5.13.1 UWP
套件。建工程时,显示编译错误很多:
代码:
testproject.pro
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
CONFIG += c++17
# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked 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 it uses 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 \
testproject.cpp
HEADERS += \
testproject.h
FORMS += \
testproject.ui
LIBS += -lwindowsapp
# Default rules for deployment.
#qnx: target.path = /tmp/$${TARGET}/bin
#else: unix:!android: target.path = /opt/$${TARGET}/bin
#!isEmpty(target.path): INSTALLS += target
testproject.h
#ifndef TESTPROJECT_H
#define TESTPROJECT_H
#include <QDialog>
#include <QDebug>
#include "winrt/Windows.System.Diagnostics.h"
using namespace winrt;
using namespace Windows::System::Diagnostics;
QT_BEGIN_NAMESPACE
namespace Ui { class TestProject; }
QT_END_NAMESPACE
class TestProject : public QDialog
{
Q_OBJECT
public:
TestProject(QWidget *parent = nullptr);
~TestProject();
private:
Ui::TestProject *ui;
};
#endif // TESTPROJECT_H
testproject.cpp
#include "testproject.h"
#include "ui_testproject.h"
TestProject::TestProject(QWidget *parent)
: QDialog(parent)
, ui(new Ui::TestProject)
{
ui->setupUi(this);
init_apartment();
auto info = SystemDiagnosticInfo::GetForCurrentSystem();
auto memory = info.MemoryUsage().GetReport().TotalPhysicalSizeInBytes();
qDebug() << memory;
}
TestProject::~TestProject()
{
delete ui;
}
没有WinRT
代码编译成功。关于如何使用 Qt
配置 WinRT
有什么想法吗? Qt
到 运行 WinRT
代码需要哪些库?提前致谢。
尝试在 #include "winrt/Windows.System.Diagnostics.h"
之前添加 #undef X64
或转到您的项目设置,select "Configuration Properties" -> "C/C++" -> "Preprocessor",在 "Preprocessor Definitions" select "Edit"[=21= 旁边的下拉列表中], 删除行 X64
。我不知道这个定义是做什么用的,但它与 Windows.System.0.h.
ProcessorArchitecture::X64
枚举冲突
PS。这个答案只是一个复制的猜测,因为我无法理解屏幕截图上的错误。通常从输出面板复制粘贴文本比错误列表提供更多信息。