带有WinRT C ++构建问题的Qt

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了带有WinRT C ++构建问题的Qt相关的知识,希望对你有一定的参考价值。

我想使用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

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代码,编译成功。有任何想法如何使用WinRT配置Qt吗? Qt运行WinRT代码需要哪些库?预先感谢。

我想使用WinRT(Windows 10)构建现代Windows应用程序。我将Qt 5.13.1 UWP套件用于Visual Studio2017。构建项目时,它显示很多编译错误:代码:...

答案
尝试在#undef X64之前添加#include "winrt/Windows.System.Diagnostics.h"或转到项目设置,在

“ Preprocessor”旁边的下拉列表中选择“ Configuration Properties”->“ C / C ++”->“ Preprocessor”

以上是关于带有WinRT C ++构建问题的Qt的主要内容,如果未能解决你的问题,请参考以下文章

使用 qt 为预构建的 c 程序构建 GUI [关闭]

构建后带有 net-snmp 的 C++ Qt5 崩溃

Jacoco和Tycho surefire的Eclipse RCP插件代码介绍

如何在 Qt 代码中访问 Qt 构建系统项目 (QBS) 变量

在 Windows 上从 Qt Creator 进入 Qt Sources(不是从源代码构建的)

在带有openGL和SDL的Linux上使用c ++时出现SIGSEGV错误