我想使用WinRT
(Windows 10)构建现代的Windows应用程序。我将Qt 5.13.1 UWP
套件用于Visual Studio 2017
。在构建项目时,它会显示很多编译错误:
码:
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
测试项目
#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
测试项目
#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
代码,它将成功编译。有什么想法如何使用WinRT
配置Qt
吗? Qt
运行WinRT
代码需要哪些库?提前致谢。 最佳答案
尝试在#undef X64
之前添加#include "winrt/Windows.System.Diagnostics.h"
或转到项目设置,选择“配置属性”->“ C / C ++”->“预处理器”,在“预处理器定义”旁边的下拉列表中选择“编辑”,然后删除X64
行。我不知道此定义的用途,但它与Windows.System.0.h中的ProcessorArchitecture::X64
枚举冲突。
PS。这个答案只是复制的猜测,因为我对屏幕截图上的错误不太了解。通常,从“输出”面板复制粘贴文本比“错误列表”提供更多信息。
关于c++ - Qt与WinRT C++构建问题,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/58436766/