0
votes

I want to build a modern Windows application using WinRT (Windows 10). I use Qt 5.13.1 UWP kits for Visual Studio 2017. When building a project, it displays a lot of compilation errors:

2019-10-16_143454.png

Code:

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;
}

Without WinRT code it compiles successfully. Any ideas how to configure WinRT using Qt? What libraries are required for Qt to run WinRT code? Thanks in advance.

1

1 Answers

1
votes

Try either adding #undef X64 before #include "winrt/Windows.System.Diagnostics.h" or go to your project settings, select "Configuration Properties" -> "C/C++" -> "Preprocessor", in the dropdown next to "Preprocessor Definitions" select "Edit", remove the line X64. I've no idea what this define is for, but it conflicts with the ProcessorArchitecture::X64 enum in Windows.System.0.h.

PS. This answer is just a reproduced guesswork as I can't make much sense of the errors on the screenshot. Usually copy-pasting the text from the Output panel is more informative than the Error List.