Author Archives: dmitriano

How I fixed “CMake configuration has no path to C++ compiler” in QT Creator

CMake did not work and there was a yellow triangle at the left side of MSVC2019 kit name:

I fixed this buy changing C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat with C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsx86_arm64.bat.

(more…)

Using QML_ELEMENT with CMake

There is an example of using QML_ELEMENT in qt5\qtdeclarative\examples\quick\scenegraph\openglunderqml and qt_add_qml_module in CMake:

qt_add_qml_module(openglunderqml
    URI OpenGLUnderQML
    VERSION 1.0
    QML_FILES main.qml
    RESOURCE_PREFIX /scenegraph/openglunderqml
    NO_RESOURCE_TARGET_PATH
)

In QML it imports the module:

import OpenGLUnderQML 1.0
(more…)

Building QT 6.2 for Windows with MSVC2019

I cloned QT repository:

git clone --recursive https://code.qt.io/qt/qt5.git --branch v6.2.0
cd qt5

Looks like the command below is not required:

./init-repository --module-subset=all

because it prints:

Will not reinitialize already initialized repository (use -f to force)!
(more…)

QtPurchasing uses deprecated AIDL billing library

Looks like QtPurchasing uses deprecated AIDL billing library and people say that it crashes on some devices. See https://developer.android.com/google/play/billing/deprecation-faq for more information. Probably they are going to update it in 5.15.7 and move it into examples in QT 6, so it is not clear exactly what will happen with it, we probably better wait QT 5.15.7 to be released.

(more…)

Adding a header to source files

Put the header content into a text file and load it into a variable:

cd ~/temp/
nano h.txt
h=$(<h.txt)
(more…)

Enabling colors in Window 10 console

Add DWORD key VirtualTerminalLevel=1 to HKEY_CURRENT_USER\Console:

(more…)

Did you already learn what are C++ concepts?

In C++20 we can do this:

#include <ranges>
#include <vector>

template <std::ranges::range Range>
    requires std::same_as<std::ranges::range_value_t<Range>, int>
auto TransformIt(Range r)
{
    return r | std::views::transform([](int n) { return n * n; });
}

int main()
{
    std::vector<int> v;
    auto r = TransformIt(v);
    return 0;
}
(more…)

std::unique_ptr with a deleter that throws an exception

The program below is terminated when the deleter throws the exception:

#include <iostream>
#include <memory>

struct X
{
    int value;
};

struct Deleter
{
    void operator()(X* p) noexcept(false)
    {
        if (p->value == 0)
        {
            throw std::logic_error("Can't delete a zero.");
        }

        delete p;
    }
};
(more…)

Invokable constructor in QT

In QT 5.15 I declare a class with an invokable constructor:

class TestClass : public QObject
{
    Q_OBJECT

public:

    Q_INVOKABLE TestClass(QString val) {}
};

Q_DECLARE_METATYPE(TestClass*)

register its type:

qRegisterMetaType<TestClass*>();
(more…)

An example of heterogeneous lookup with std::unordered_set in C++20

std::unordered_set has a template find function in C++20. To make it work I define a custom hash and a custom equality compares as follows:

struct BotSettings
{
    std::string type;
    std::string name;
    bool started;
};
(more…)