Qt with WinRT C++ build issue
-
Hello!
I want to build a modern Windows application using
WinRT
(Windows 10). I useQt 5.13.1 UWP
kits forVisual Studio 2017
. When building a project, it displays a lot of compilation errors:Code:
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; }
Without
WinRT
code it compiles successfully. Any ideas how to fix these issues? Thanks. -
Also, I have tried to set a color for the titlebar:
auto titleBar = ApplicationView::GetForCurrentView()->TitleBar; titleBar->BackgroundColor = ColorHelper::FromArgb(211, 211, 211, 211); titleBar->ButtonBackgroundColor = ColorHelper::FromArgb(211, 211, 211, 211);
But these issues still exists:
I think something is missing using
Qt
, because the same project complies successfully using Visual Studio 2017 / 2019. -
I tried to run @Chris-Kawa example from here: https://forum.qt.io/topic/68670/how-can-i-use-winrt-c-apis-in-at-qt-winrt-app/13
It returns the following issues:
Any ideas how to configure
WinRT
usingQt
? What libraries are required forQt
to runWinRT
code? Thanks in advance. -
I have fixed the issue by adding
#undef X64
before#include "winrt/Windows.System.Diagnostics.h"
. For some reason this define conflicts with theProcessorArchitecture::X64 enum
inWindows.System.0.h
as stated byVVV
user from: https://stackoverflow.com/questions/58436766/qt-with-winrt-c-build-issue/58440774#58440774. The issue is resolved.