Explore all Qt5 open source software, libraries, packages, source code, cloud functions and APIs.

Popular New Releases in Qt5

flameshot

shotcut

fontforge

FontForge March 2022 Release

wxWidgets

wxWidgets 3.1.6

fbs

Fix `sign` command on Windows 10 > 20236

Popular Libraries in Qt5

flameshot

by flameshot-org doticonc++doticon

star image 17086 doticonGPL-3.0

Powerful yet simple to use screenshot software :desktop_computer: :camera_flash:

pan-light

by peterq doticongodoticon

star image 11642 doticonLGPL-3.0

百度网盘不限速客户端, golang + qt5, 跨平台图形界面

jd-gui

by java-decompiler doticonjavadoticon

star image 10089 doticonGPL-3.0

A standalone Java Decompiler GUI

shadowsocks-qt5

by shadowsocks doticonc++doticon

star image 7850 doticonLGPL-3.0

A cross-platform shadowsocks GUI client

transmission

by transmission doticonc++doticon

star image 6743 doticonNOASSERTION

Official Transmission BitTorrent client repository

shotcut

by mltframework doticonc++doticon

star image 6225 doticonGPL-3.0

cross-platform (Qt), open-source (GPLv3) video editor

persepolis

by persepolisdm doticonpythondoticon

star image 4923 doticonGPL-3.0

Persepolis Download Manager is a GUI for aria2.

fontforge

by fontforge doticoncdoticon

star image 4243 doticonNOASSERTION

Free (libre) font editor for Windows, Mac OS X and GNU+Linux

wxWidgets

by wxWidgets doticonc++doticon

star image 4215 doticon

Cross-Platform C++ GUI Library

Trending New libraries in Qt5

winstall

by MehediH doticonjavascriptdoticon

star image 610 doticonGPL-3.0

A web app for browsing and installing Windows Package Manager apps.

ReplaySorcery

by matanui159 doticoncdoticon

star image 593 doticonGPL-3.0

An open-source, instant-replay solution for Linux

Lightly

by Luwx doticonc++doticon

star image 506 doticonNOASSERTION

A modern style for qt applications.

wormhole-gui

by Jacalz doticongodoticon

star image 431 doticonGPL-3.0

Cross-platform application for easy encrypted sharing of files, folders, and text between devices.

spotify-qt

by kraxarn doticonc++doticon

star image 394 doticonGPL-3.0

Lightweight Spotify client using Qt

framelesshelper

by wangwenx190 doticonc++doticon

star image 348 doticonMIT

Frameless windows for Qt Widgets and Qt Quick applications. Support Win32, X11, Wayland and macOS.

solid-start

by solidjs doticontypescriptdoticon

star image 293 doticonMIT

SolidStart is Solid's official starter

KindleHelper

by Peach-Coding doticonpythondoticon

star image 292 doticonGPL-3.0

kindle助手,kindle最好的伙伴

KDiskMark

by JonMagon doticonc++doticon

star image 259 doticonGPL-3.0

A simple open-source disk benchmark tool for Linux distros

Top Authors in Qt5

1

KDE

54 Libraries

star icon3706

2

qt

25 Libraries

star icon4119

3

sonichy

19 Libraries

star icon152

4

lirios

18 Libraries

star icon227

5

linuxdeepin

13 Libraries

star icon706

6

PacktPublishing

13 Libraries

star icon584

7

KDAB

12 Libraries

star icon1067

8

GNOME

10 Libraries

star icon504

9

lxqt

10 Libraries

star icon964

10

Skycoder42

8 Libraries

star icon47

1

54 Libraries

star icon3706

2

25 Libraries

star icon4119

3

19 Libraries

star icon152

4

18 Libraries

star icon227

5

13 Libraries

star icon706

6

13 Libraries

star icon584

7

12 Libraries

star icon1067

8

10 Libraries

star icon504

9

10 Libraries

star icon964

10

8 Libraries

star icon47

Trending Kits in Qt5

No Trending Kits are available at this moment for Qt5

Trending Discussions on Qt5

Why aren't my Qt5 language translations loading?

Combining Qt with OpenGL: does not compile

Qt 5 Disabling Click-and-Hold

Does QtNetworkAuth support PKCE

Changing QThread variable from a sub window

Is there a way to access QMainWindowPrivate or QMainWindowLayout?

Build and run a Qt application on macOS via Bazel

CMake: How to compile with different library versions of Qt?

How to install websockets for Qt 6?

How to make unique_ptr work with Qt's QHash and QString?

QUESTION

Why aren't my Qt5 language translations loading?

Asked 2022-Apr-01 at 16:09

I am trying to write a simple qml application with language translations using CMake and although the application runs, it never shows translations. I'm on a Linux platform with CMake version 3.22.2 and Qt version 3.15.2 Here is the directory structure:

1├── CMakeLists.txt
2└── src
3    ├── CMakeLists.txt
4    ├── main.cpp
5    ├── silly.qrc
6    └── qml
7        ├── silly.qml
8        └── translations
9            ├── qml_de.ts
10            ├── qml_en.ts
11            └── qml_fr.ts
12
CMakeLists.txt
1├── CMakeLists.txt
2└── src
3    ├── CMakeLists.txt
4    ├── main.cpp
5    ├── silly.qrc
6    └── qml
7        ├── silly.qml
8        └── translations
9            ├── qml_de.ts
10            ├── qml_en.ts
11            └── qml_fr.ts
12cmake_minimum_required(VERSION 3.22)
13project(silly VERSION 1.0.0)
14add_subdirectory(src)
15
src/CMakeLists.txt
1├── CMakeLists.txt
2└── src
3    ├── CMakeLists.txt
4    ├── main.cpp
5    ├── silly.qrc
6    └── qml
7        ├── silly.qml
8        └── translations
9            ├── qml_de.ts
10            ├── qml_en.ts
11            └── qml_fr.ts
12cmake_minimum_required(VERSION 3.22)
13project(silly VERSION 1.0.0)
14add_subdirectory(src)
15cmake_minimum_required(VERSION 3.22)
16find_package(Qt5 COMPONENTS Qml Quick LinguistTools REQUIRED)
17set(TRANSLATIONS 
18    qml/translations/qml_en.ts
19    qml/translations/qml_fr.ts
20    qml/translations/qml_de.ts
21)
22qt5_create_translation(QM_FILES ${CMAKE_CURRENT_SOURCE_DIR} ${TRANSLATIONS})
23qt5_add_resources(QRC_RESOURCES "silly.qrc") 
24
25add_executable(silly main.cpp 
26    "${QRC_RESOURCES}"
27    "${QM_FILES}"
28)
29target_compile_features(silly PUBLIC cxx_std_17)
30set_target_properties(silly PROPERTIES AUTOMOC ON AUTORCC ON)
31target_link_libraries(silly PRIVATE Qt5::Quick Qt5::Qml)
32target_include_directories(silly
33    PUBLIC
34        $<INSTALL_INTERFACE:.>
35        $<BUILD_INTERFACE:${CMAKE_BINARY_DIR}>
36)
37install(TARGETS silly)
38
src/main.cpp
1├── CMakeLists.txt
2└── src
3    ├── CMakeLists.txt
4    ├── main.cpp
5    ├── silly.qrc
6    └── qml
7        ├── silly.qml
8        └── translations
9            ├── qml_de.ts
10            ├── qml_en.ts
11            └── qml_fr.ts
12cmake_minimum_required(VERSION 3.22)
13project(silly VERSION 1.0.0)
14add_subdirectory(src)
15cmake_minimum_required(VERSION 3.22)
16find_package(Qt5 COMPONENTS Qml Quick LinguistTools REQUIRED)
17set(TRANSLATIONS 
18    qml/translations/qml_en.ts
19    qml/translations/qml_fr.ts
20    qml/translations/qml_de.ts
21)
22qt5_create_translation(QM_FILES ${CMAKE_CURRENT_SOURCE_DIR} ${TRANSLATIONS})
23qt5_add_resources(QRC_RESOURCES "silly.qrc") 
24
25add_executable(silly main.cpp 
26    "${QRC_RESOURCES}"
27    "${QM_FILES}"
28)
29target_compile_features(silly PUBLIC cxx_std_17)
30set_target_properties(silly PROPERTIES AUTOMOC ON AUTORCC ON)
31target_link_libraries(silly PRIVATE Qt5::Quick Qt5::Qml)
32target_include_directories(silly
33    PUBLIC
34        $<INSTALL_INTERFACE:.>
35        $<BUILD_INTERFACE:${CMAKE_BINARY_DIR}>
36)
37install(TARGETS silly)
38#include <QGuiApplication>
39#include <QQmlApplicationEngine>
40
41int main(int argc, char *argv[])
42{
43    QGuiApplication app(argc, argv);
44    QQmlApplicationEngine engine;
45    engine.addImportPath("qrc:/");
46    engine.load(QUrl("qrc:/qml/silly.qml"));
47
48    return app.exec();
49}
50
src/silly.qrc
1├── CMakeLists.txt
2└── src
3    ├── CMakeLists.txt
4    ├── main.cpp
5    ├── silly.qrc
6    └── qml
7        ├── silly.qml
8        └── translations
9            ├── qml_de.ts
10            ├── qml_en.ts
11            └── qml_fr.ts
12cmake_minimum_required(VERSION 3.22)
13project(silly VERSION 1.0.0)
14add_subdirectory(src)
15cmake_minimum_required(VERSION 3.22)
16find_package(Qt5 COMPONENTS Qml Quick LinguistTools REQUIRED)
17set(TRANSLATIONS 
18    qml/translations/qml_en.ts
19    qml/translations/qml_fr.ts
20    qml/translations/qml_de.ts
21)
22qt5_create_translation(QM_FILES ${CMAKE_CURRENT_SOURCE_DIR} ${TRANSLATIONS})
23qt5_add_resources(QRC_RESOURCES "silly.qrc") 
24
25add_executable(silly main.cpp 
26    "${QRC_RESOURCES}"
27    "${QM_FILES}"
28)
29target_compile_features(silly PUBLIC cxx_std_17)
30set_target_properties(silly PROPERTIES AUTOMOC ON AUTORCC ON)
31target_link_libraries(silly PRIVATE Qt5::Quick Qt5::Qml)
32target_include_directories(silly
33    PUBLIC
34        $<INSTALL_INTERFACE:.>
35        $<BUILD_INTERFACE:${CMAKE_BINARY_DIR}>
36)
37install(TARGETS silly)
38#include <QGuiApplication>
39#include <QQmlApplicationEngine>
40
41int main(int argc, char *argv[])
42{
43    QGuiApplication app(argc, argv);
44    QQmlApplicationEngine engine;
45    engine.addImportPath("qrc:/");
46    engine.load(QUrl("qrc:/qml/silly.qml"));
47
48    return app.exec();
49}
50<!DOCTYPE RCC><RCC version="1.0">
51    <qresource prefix="/qml">
52        <file alias="silly.qml">qml/silly.qml</file>
53    </qresource>
54</RCC>
55
src/qml/silly.qml
1├── CMakeLists.txt
2└── src
3    ├── CMakeLists.txt
4    ├── main.cpp
5    ├── silly.qrc
6    └── qml
7        ├── silly.qml
8        └── translations
9            ├── qml_de.ts
10            ├── qml_en.ts
11            └── qml_fr.ts
12cmake_minimum_required(VERSION 3.22)
13project(silly VERSION 1.0.0)
14add_subdirectory(src)
15cmake_minimum_required(VERSION 3.22)
16find_package(Qt5 COMPONENTS Qml Quick LinguistTools REQUIRED)
17set(TRANSLATIONS 
18    qml/translations/qml_en.ts
19    qml/translations/qml_fr.ts
20    qml/translations/qml_de.ts
21)
22qt5_create_translation(QM_FILES ${CMAKE_CURRENT_SOURCE_DIR} ${TRANSLATIONS})
23qt5_add_resources(QRC_RESOURCES "silly.qrc") 
24
25add_executable(silly main.cpp 
26    "${QRC_RESOURCES}"
27    "${QM_FILES}"
28)
29target_compile_features(silly PUBLIC cxx_std_17)
30set_target_properties(silly PROPERTIES AUTOMOC ON AUTORCC ON)
31target_link_libraries(silly PRIVATE Qt5::Quick Qt5::Qml)
32target_include_directories(silly
33    PUBLIC
34        $<INSTALL_INTERFACE:.>
35        $<BUILD_INTERFACE:${CMAKE_BINARY_DIR}>
36)
37install(TARGETS silly)
38#include <QGuiApplication>
39#include <QQmlApplicationEngine>
40
41int main(int argc, char *argv[])
42{
43    QGuiApplication app(argc, argv);
44    QQmlApplicationEngine engine;
45    engine.addImportPath("qrc:/");
46    engine.load(QUrl("qrc:/qml/silly.qml"));
47
48    return app.exec();
49}
50<!DOCTYPE RCC><RCC version="1.0">
51    <qresource prefix="/qml">
52        <file alias="silly.qml">qml/silly.qml</file>
53    </qresource>
54</RCC>
55import QtQuick 2.15
56import QtQuick.Window 2.15
57import QtQuick.Controls 2.15
58
59ApplicationWindow {
60    visible: true
61
62    Button {
63        anchors.fill: parent
64        spacing: 20
65        text: qsTr("Hello")
66    }
67}
68
src/qml/translations/qml_de.ts
1├── CMakeLists.txt
2└── src
3    ├── CMakeLists.txt
4    ├── main.cpp
5    ├── silly.qrc
6    └── qml
7        ├── silly.qml
8        └── translations
9            ├── qml_de.ts
10            ├── qml_en.ts
11            └── qml_fr.ts
12cmake_minimum_required(VERSION 3.22)
13project(silly VERSION 1.0.0)
14add_subdirectory(src)
15cmake_minimum_required(VERSION 3.22)
16find_package(Qt5 COMPONENTS Qml Quick LinguistTools REQUIRED)
17set(TRANSLATIONS 
18    qml/translations/qml_en.ts
19    qml/translations/qml_fr.ts
20    qml/translations/qml_de.ts
21)
22qt5_create_translation(QM_FILES ${CMAKE_CURRENT_SOURCE_DIR} ${TRANSLATIONS})
23qt5_add_resources(QRC_RESOURCES "silly.qrc") 
24
25add_executable(silly main.cpp 
26    "${QRC_RESOURCES}"
27    "${QM_FILES}"
28)
29target_compile_features(silly PUBLIC cxx_std_17)
30set_target_properties(silly PROPERTIES AUTOMOC ON AUTORCC ON)
31target_link_libraries(silly PRIVATE Qt5::Quick Qt5::Qml)
32target_include_directories(silly
33    PUBLIC
34        $<INSTALL_INTERFACE:.>
35        $<BUILD_INTERFACE:${CMAKE_BINARY_DIR}>
36)
37install(TARGETS silly)
38#include <QGuiApplication>
39#include <QQmlApplicationEngine>
40
41int main(int argc, char *argv[])
42{
43    QGuiApplication app(argc, argv);
44    QQmlApplicationEngine engine;
45    engine.addImportPath("qrc:/");
46    engine.load(QUrl("qrc:/qml/silly.qml"));
47
48    return app.exec();
49}
50<!DOCTYPE RCC><RCC version="1.0">
51    <qresource prefix="/qml">
52        <file alias="silly.qml">qml/silly.qml</file>
53    </qresource>
54</RCC>
55import QtQuick 2.15
56import QtQuick.Window 2.15
57import QtQuick.Controls 2.15
58
59ApplicationWindow {
60    visible: true
61
62    Button {
63        anchors.fill: parent
64        spacing: 20
65        text: qsTr("Hello")
66    }
67}
68<?xml version="1.0" encoding="utf-8"?>
69<!DOCTYPE TS>
70<TS version="2.1" language="de_DE">
71<context>
72    <name>silly</name>
73    <message>
74        <location filename="../silly.qml" line="11"/>
75        <source>Hello</source>
76        <translation>Hallo</translation>
77    </message>
78</context>
79</TS>
80
src/qml/translations/qml_en.ts
1├── CMakeLists.txt
2└── src
3    ├── CMakeLists.txt
4    ├── main.cpp
5    ├── silly.qrc
6    └── qml
7        ├── silly.qml
8        └── translations
9            ├── qml_de.ts
10            ├── qml_en.ts
11            └── qml_fr.ts
12cmake_minimum_required(VERSION 3.22)
13project(silly VERSION 1.0.0)
14add_subdirectory(src)
15cmake_minimum_required(VERSION 3.22)
16find_package(Qt5 COMPONENTS Qml Quick LinguistTools REQUIRED)
17set(TRANSLATIONS 
18    qml/translations/qml_en.ts
19    qml/translations/qml_fr.ts
20    qml/translations/qml_de.ts
21)
22qt5_create_translation(QM_FILES ${CMAKE_CURRENT_SOURCE_DIR} ${TRANSLATIONS})
23qt5_add_resources(QRC_RESOURCES "silly.qrc") 
24
25add_executable(silly main.cpp 
26    "${QRC_RESOURCES}"
27    "${QM_FILES}"
28)
29target_compile_features(silly PUBLIC cxx_std_17)
30set_target_properties(silly PROPERTIES AUTOMOC ON AUTORCC ON)
31target_link_libraries(silly PRIVATE Qt5::Quick Qt5::Qml)
32target_include_directories(silly
33    PUBLIC
34        $<INSTALL_INTERFACE:.>
35        $<BUILD_INTERFACE:${CMAKE_BINARY_DIR}>
36)
37install(TARGETS silly)
38#include <QGuiApplication>
39#include <QQmlApplicationEngine>
40
41int main(int argc, char *argv[])
42{
43    QGuiApplication app(argc, argv);
44    QQmlApplicationEngine engine;
45    engine.addImportPath("qrc:/");
46    engine.load(QUrl("qrc:/qml/silly.qml"));
47
48    return app.exec();
49}
50<!DOCTYPE RCC><RCC version="1.0">
51    <qresource prefix="/qml">
52        <file alias="silly.qml">qml/silly.qml</file>
53    </qresource>
54</RCC>
55import QtQuick 2.15
56import QtQuick.Window 2.15
57import QtQuick.Controls 2.15
58
59ApplicationWindow {
60    visible: true
61
62    Button {
63        anchors.fill: parent
64        spacing: 20
65        text: qsTr("Hello")
66    }
67}
68<?xml version="1.0" encoding="utf-8"?>
69<!DOCTYPE TS>
70<TS version="2.1" language="de_DE">
71<context>
72    <name>silly</name>
73    <message>
74        <location filename="../silly.qml" line="11"/>
75        <source>Hello</source>
76        <translation>Hallo</translation>
77    </message>
78</context>
79</TS>
80<?xml version="1.0" encoding="utf-8"?>
81<!DOCTYPE TS>
82<TS version="2.1" language="en_US">
83<context>
84    <name>silly</name>
85    <message>
86        <location filename="../silly.qml" line="11"/>
87        <source>Hello</source>
88        <translation type="unfinished"></translation>
89    </message>
90</context>
91</TS>
92
src/qml/translations/qml_fr.ts
1├── CMakeLists.txt
2└── src
3    ├── CMakeLists.txt
4    ├── main.cpp
5    ├── silly.qrc
6    └── qml
7        ├── silly.qml
8        └── translations
9            ├── qml_de.ts
10            ├── qml_en.ts
11            └── qml_fr.ts
12cmake_minimum_required(VERSION 3.22)
13project(silly VERSION 1.0.0)
14add_subdirectory(src)
15cmake_minimum_required(VERSION 3.22)
16find_package(Qt5 COMPONENTS Qml Quick LinguistTools REQUIRED)
17set(TRANSLATIONS 
18    qml/translations/qml_en.ts
19    qml/translations/qml_fr.ts
20    qml/translations/qml_de.ts
21)
22qt5_create_translation(QM_FILES ${CMAKE_CURRENT_SOURCE_DIR} ${TRANSLATIONS})
23qt5_add_resources(QRC_RESOURCES "silly.qrc") 
24
25add_executable(silly main.cpp 
26    "${QRC_RESOURCES}"
27    "${QM_FILES}"
28)
29target_compile_features(silly PUBLIC cxx_std_17)
30set_target_properties(silly PROPERTIES AUTOMOC ON AUTORCC ON)
31target_link_libraries(silly PRIVATE Qt5::Quick Qt5::Qml)
32target_include_directories(silly
33    PUBLIC
34        $<INSTALL_INTERFACE:.>
35        $<BUILD_INTERFACE:${CMAKE_BINARY_DIR}>
36)
37install(TARGETS silly)
38#include <QGuiApplication>
39#include <QQmlApplicationEngine>
40
41int main(int argc, char *argv[])
42{
43    QGuiApplication app(argc, argv);
44    QQmlApplicationEngine engine;
45    engine.addImportPath("qrc:/");
46    engine.load(QUrl("qrc:/qml/silly.qml"));
47
48    return app.exec();
49}
50<!DOCTYPE RCC><RCC version="1.0">
51    <qresource prefix="/qml">
52        <file alias="silly.qml">qml/silly.qml</file>
53    </qresource>
54</RCC>
55import QtQuick 2.15
56import QtQuick.Window 2.15
57import QtQuick.Controls 2.15
58
59ApplicationWindow {
60    visible: true
61
62    Button {
63        anchors.fill: parent
64        spacing: 20
65        text: qsTr("Hello")
66    }
67}
68<?xml version="1.0" encoding="utf-8"?>
69<!DOCTYPE TS>
70<TS version="2.1" language="de_DE">
71<context>
72    <name>silly</name>
73    <message>
74        <location filename="../silly.qml" line="11"/>
75        <source>Hello</source>
76        <translation>Hallo</translation>
77    </message>
78</context>
79</TS>
80<?xml version="1.0" encoding="utf-8"?>
81<!DOCTYPE TS>
82<TS version="2.1" language="en_US">
83<context>
84    <name>silly</name>
85    <message>
86        <location filename="../silly.qml" line="11"/>
87        <source>Hello</source>
88        <translation type="unfinished"></translation>
89    </message>
90</context>
91</TS>
92<?xml version="1.0" encoding="utf-8"?>
93<!DOCTYPE TS>
94<TS version="2.1" language="fr_FR">
95<context>
96    <name>silly</name>
97    <message>
98        <location filename="../silly.qml" line="11"/>
99        <source>Hello</source>
100        <translation>Bonjour</translation>
101    </message>
102</context>
103</TS>
104

It builds and runs with no errors, but when I attempt to test with this: LANGUAGE=fr src/silly I get a button that says "Hello" instead of a button that says "Bonjour". I've been trying to figure this out for hours which also leads me to the secondary question: how does one generally troubleshoot Qt language translations? This is my first time and I could find no documentation on that.

ANSWER

Answered 2022-Apr-01 at 16:09

That's pretty badly documented stuff which works magically with ready-made example using dedicated qmake configuration parameter embed_translations. I advice you to take a look into the original example's build dir where .qm files and a special qrc file qmake_qmake_qm_files.qrc get generated.

You don't need to use QTranslator unless you want to support dynamic language switch. At startup, QML runtime automatically loads a translation file qml_<language_COUNTRY>.qm (qml_xx_XX.qm where xx is ISO639 and XX is optional ISO 3166 code) from the i18n subdirectory of the root QML file, based on the system language, if it finds one.

You need to get your .qm files to qrc:/qml/i18n/ folder because your main qml file is in qrc:/qml/.

With CMake you can do it as follows:

Add a new qrc file, e.g. cmake_qm_files.qrc to your project

1├── CMakeLists.txt
2└── src
3    ├── CMakeLists.txt
4    ├── main.cpp
5    ├── silly.qrc
6    └── qml
7        ├── silly.qml
8        └── translations
9            ├── qml_de.ts
10            ├── qml_en.ts
11            └── qml_fr.ts
12cmake_minimum_required(VERSION 3.22)
13project(silly VERSION 1.0.0)
14add_subdirectory(src)
15cmake_minimum_required(VERSION 3.22)
16find_package(Qt5 COMPONENTS Qml Quick LinguistTools REQUIRED)
17set(TRANSLATIONS 
18    qml/translations/qml_en.ts
19    qml/translations/qml_fr.ts
20    qml/translations/qml_de.ts
21)
22qt5_create_translation(QM_FILES ${CMAKE_CURRENT_SOURCE_DIR} ${TRANSLATIONS})
23qt5_add_resources(QRC_RESOURCES &quot;silly.qrc&quot;) 
24
25add_executable(silly main.cpp 
26    &quot;${QRC_RESOURCES}&quot;
27    &quot;${QM_FILES}&quot;
28)
29target_compile_features(silly PUBLIC cxx_std_17)
30set_target_properties(silly PROPERTIES AUTOMOC ON AUTORCC ON)
31target_link_libraries(silly PRIVATE Qt5::Quick Qt5::Qml)
32target_include_directories(silly
33    PUBLIC
34        $&lt;INSTALL_INTERFACE:.&gt;
35        $&lt;BUILD_INTERFACE:${CMAKE_BINARY_DIR}&gt;
36)
37install(TARGETS silly)
38#include &lt;QGuiApplication&gt;
39#include &lt;QQmlApplicationEngine&gt;
40
41int main(int argc, char *argv[])
42{
43    QGuiApplication app(argc, argv);
44    QQmlApplicationEngine engine;
45    engine.addImportPath(&quot;qrc:/&quot;);
46    engine.load(QUrl(&quot;qrc:/qml/silly.qml&quot;));
47
48    return app.exec();
49}
50&lt;!DOCTYPE RCC&gt;&lt;RCC version=&quot;1.0&quot;&gt;
51    &lt;qresource prefix=&quot;/qml&quot;&gt;
52        &lt;file alias=&quot;silly.qml&quot;&gt;qml/silly.qml&lt;/file&gt;
53    &lt;/qresource&gt;
54&lt;/RCC&gt;
55import QtQuick 2.15
56import QtQuick.Window 2.15
57import QtQuick.Controls 2.15
58
59ApplicationWindow {
60    visible: true
61
62    Button {
63        anchors.fill: parent
64        spacing: 20
65        text: qsTr(&quot;Hello&quot;)
66    }
67}
68&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
69&lt;!DOCTYPE TS&gt;
70&lt;TS version=&quot;2.1&quot; language=&quot;de_DE&quot;&gt;
71&lt;context&gt;
72    &lt;name&gt;silly&lt;/name&gt;
73    &lt;message&gt;
74        &lt;location filename=&quot;../silly.qml&quot; line=&quot;11&quot;/&gt;
75        &lt;source&gt;Hello&lt;/source&gt;
76        &lt;translation&gt;Hallo&lt;/translation&gt;
77    &lt;/message&gt;
78&lt;/context&gt;
79&lt;/TS&gt;
80&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
81&lt;!DOCTYPE TS&gt;
82&lt;TS version=&quot;2.1&quot; language=&quot;en_US&quot;&gt;
83&lt;context&gt;
84    &lt;name&gt;silly&lt;/name&gt;
85    &lt;message&gt;
86        &lt;location filename=&quot;../silly.qml&quot; line=&quot;11&quot;/&gt;
87        &lt;source&gt;Hello&lt;/source&gt;
88        &lt;translation type=&quot;unfinished&quot;&gt;&lt;/translation&gt;
89    &lt;/message&gt;
90&lt;/context&gt;
91&lt;/TS&gt;
92&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
93&lt;!DOCTYPE TS&gt;
94&lt;TS version=&quot;2.1&quot; language=&quot;fr_FR&quot;&gt;
95&lt;context&gt;
96    &lt;name&gt;silly&lt;/name&gt;
97    &lt;message&gt;
98        &lt;location filename=&quot;../silly.qml&quot; line=&quot;11&quot;/&gt;
99        &lt;source&gt;Hello&lt;/source&gt;
100        &lt;translation&gt;Bonjour&lt;/translation&gt;
101    &lt;/message&gt;
102&lt;/context&gt;
103&lt;/TS&gt;
104&lt;RCC&gt;
105    &lt;qresource prefix=&quot;/qml/i18n&quot;&gt;
106        &lt;file&gt;qml_de.qm&lt;/file&gt;
107        &lt;file&gt;qml_en.qm&lt;/file&gt;
108        &lt;file&gt;qml_fr.qm&lt;/file&gt;
109    &lt;/qresource&gt;
110&lt;/RCC&gt;
111

Get CMake to copy the qrc file to binary dir where .qm files get created

1├── CMakeLists.txt
2└── src
3    ├── CMakeLists.txt
4    ├── main.cpp
5    ├── silly.qrc
6    └── qml
7        ├── silly.qml
8        └── translations
9            ├── qml_de.ts
10            ├── qml_en.ts
11            └── qml_fr.ts
12cmake_minimum_required(VERSION 3.22)
13project(silly VERSION 1.0.0)
14add_subdirectory(src)
15cmake_minimum_required(VERSION 3.22)
16find_package(Qt5 COMPONENTS Qml Quick LinguistTools REQUIRED)
17set(TRANSLATIONS 
18    qml/translations/qml_en.ts
19    qml/translations/qml_fr.ts
20    qml/translations/qml_de.ts
21)
22qt5_create_translation(QM_FILES ${CMAKE_CURRENT_SOURCE_DIR} ${TRANSLATIONS})
23qt5_add_resources(QRC_RESOURCES &quot;silly.qrc&quot;) 
24
25add_executable(silly main.cpp 
26    &quot;${QRC_RESOURCES}&quot;
27    &quot;${QM_FILES}&quot;
28)
29target_compile_features(silly PUBLIC cxx_std_17)
30set_target_properties(silly PROPERTIES AUTOMOC ON AUTORCC ON)
31target_link_libraries(silly PRIVATE Qt5::Quick Qt5::Qml)
32target_include_directories(silly
33    PUBLIC
34        $&lt;INSTALL_INTERFACE:.&gt;
35        $&lt;BUILD_INTERFACE:${CMAKE_BINARY_DIR}&gt;
36)
37install(TARGETS silly)
38#include &lt;QGuiApplication&gt;
39#include &lt;QQmlApplicationEngine&gt;
40
41int main(int argc, char *argv[])
42{
43    QGuiApplication app(argc, argv);
44    QQmlApplicationEngine engine;
45    engine.addImportPath(&quot;qrc:/&quot;);
46    engine.load(QUrl(&quot;qrc:/qml/silly.qml&quot;));
47
48    return app.exec();
49}
50&lt;!DOCTYPE RCC&gt;&lt;RCC version=&quot;1.0&quot;&gt;
51    &lt;qresource prefix=&quot;/qml&quot;&gt;
52        &lt;file alias=&quot;silly.qml&quot;&gt;qml/silly.qml&lt;/file&gt;
53    &lt;/qresource&gt;
54&lt;/RCC&gt;
55import QtQuick 2.15
56import QtQuick.Window 2.15
57import QtQuick.Controls 2.15
58
59ApplicationWindow {
60    visible: true
61
62    Button {
63        anchors.fill: parent
64        spacing: 20
65        text: qsTr(&quot;Hello&quot;)
66    }
67}
68&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
69&lt;!DOCTYPE TS&gt;
70&lt;TS version=&quot;2.1&quot; language=&quot;de_DE&quot;&gt;
71&lt;context&gt;
72    &lt;name&gt;silly&lt;/name&gt;
73    &lt;message&gt;
74        &lt;location filename=&quot;../silly.qml&quot; line=&quot;11&quot;/&gt;
75        &lt;source&gt;Hello&lt;/source&gt;
76        &lt;translation&gt;Hallo&lt;/translation&gt;
77    &lt;/message&gt;
78&lt;/context&gt;
79&lt;/TS&gt;
80&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
81&lt;!DOCTYPE TS&gt;
82&lt;TS version=&quot;2.1&quot; language=&quot;en_US&quot;&gt;
83&lt;context&gt;
84    &lt;name&gt;silly&lt;/name&gt;
85    &lt;message&gt;
86        &lt;location filename=&quot;../silly.qml&quot; line=&quot;11&quot;/&gt;
87        &lt;source&gt;Hello&lt;/source&gt;
88        &lt;translation type=&quot;unfinished&quot;&gt;&lt;/translation&gt;
89    &lt;/message&gt;
90&lt;/context&gt;
91&lt;/TS&gt;
92&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
93&lt;!DOCTYPE TS&gt;
94&lt;TS version=&quot;2.1&quot; language=&quot;fr_FR&quot;&gt;
95&lt;context&gt;
96    &lt;name&gt;silly&lt;/name&gt;
97    &lt;message&gt;
98        &lt;location filename=&quot;../silly.qml&quot; line=&quot;11&quot;/&gt;
99        &lt;source&gt;Hello&lt;/source&gt;
100        &lt;translation&gt;Bonjour&lt;/translation&gt;
101    &lt;/message&gt;
102&lt;/context&gt;
103&lt;/TS&gt;
104&lt;RCC&gt;
105    &lt;qresource prefix=&quot;/qml/i18n&quot;&gt;
106        &lt;file&gt;qml_de.qm&lt;/file&gt;
107        &lt;file&gt;qml_en.qm&lt;/file&gt;
108        &lt;file&gt;qml_fr.qm&lt;/file&gt;
109    &lt;/qresource&gt;
110&lt;/RCC&gt;
111configure_file(cmake_qm_files.qrc ${CMAKE_BINARY_DIR} COPYONLY)
112

Get qrc file resource compiled and embedded to your executable

1├── CMakeLists.txt
2└── src
3    ├── CMakeLists.txt
4    ├── main.cpp
5    ├── silly.qrc
6    └── qml
7        ├── silly.qml
8        └── translations
9            ├── qml_de.ts
10            ├── qml_en.ts
11            └── qml_fr.ts
12cmake_minimum_required(VERSION 3.22)
13project(silly VERSION 1.0.0)
14add_subdirectory(src)
15cmake_minimum_required(VERSION 3.22)
16find_package(Qt5 COMPONENTS Qml Quick LinguistTools REQUIRED)
17set(TRANSLATIONS 
18    qml/translations/qml_en.ts
19    qml/translations/qml_fr.ts
20    qml/translations/qml_de.ts
21)
22qt5_create_translation(QM_FILES ${CMAKE_CURRENT_SOURCE_DIR} ${TRANSLATIONS})
23qt5_add_resources(QRC_RESOURCES &quot;silly.qrc&quot;) 
24
25add_executable(silly main.cpp 
26    &quot;${QRC_RESOURCES}&quot;
27    &quot;${QM_FILES}&quot;
28)
29target_compile_features(silly PUBLIC cxx_std_17)
30set_target_properties(silly PROPERTIES AUTOMOC ON AUTORCC ON)
31target_link_libraries(silly PRIVATE Qt5::Quick Qt5::Qml)
32target_include_directories(silly
33    PUBLIC
34        $&lt;INSTALL_INTERFACE:.&gt;
35        $&lt;BUILD_INTERFACE:${CMAKE_BINARY_DIR}&gt;
36)
37install(TARGETS silly)
38#include &lt;QGuiApplication&gt;
39#include &lt;QQmlApplicationEngine&gt;
40
41int main(int argc, char *argv[])
42{
43    QGuiApplication app(argc, argv);
44    QQmlApplicationEngine engine;
45    engine.addImportPath(&quot;qrc:/&quot;);
46    engine.load(QUrl(&quot;qrc:/qml/silly.qml&quot;));
47
48    return app.exec();
49}
50&lt;!DOCTYPE RCC&gt;&lt;RCC version=&quot;1.0&quot;&gt;
51    &lt;qresource prefix=&quot;/qml&quot;&gt;
52        &lt;file alias=&quot;silly.qml&quot;&gt;qml/silly.qml&lt;/file&gt;
53    &lt;/qresource&gt;
54&lt;/RCC&gt;
55import QtQuick 2.15
56import QtQuick.Window 2.15
57import QtQuick.Controls 2.15
58
59ApplicationWindow {
60    visible: true
61
62    Button {
63        anchors.fill: parent
64        spacing: 20
65        text: qsTr(&quot;Hello&quot;)
66    }
67}
68&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
69&lt;!DOCTYPE TS&gt;
70&lt;TS version=&quot;2.1&quot; language=&quot;de_DE&quot;&gt;
71&lt;context&gt;
72    &lt;name&gt;silly&lt;/name&gt;
73    &lt;message&gt;
74        &lt;location filename=&quot;../silly.qml&quot; line=&quot;11&quot;/&gt;
75        &lt;source&gt;Hello&lt;/source&gt;
76        &lt;translation&gt;Hallo&lt;/translation&gt;
77    &lt;/message&gt;
78&lt;/context&gt;
79&lt;/TS&gt;
80&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
81&lt;!DOCTYPE TS&gt;
82&lt;TS version=&quot;2.1&quot; language=&quot;en_US&quot;&gt;
83&lt;context&gt;
84    &lt;name&gt;silly&lt;/name&gt;
85    &lt;message&gt;
86        &lt;location filename=&quot;../silly.qml&quot; line=&quot;11&quot;/&gt;
87        &lt;source&gt;Hello&lt;/source&gt;
88        &lt;translation type=&quot;unfinished&quot;&gt;&lt;/translation&gt;
89    &lt;/message&gt;
90&lt;/context&gt;
91&lt;/TS&gt;
92&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
93&lt;!DOCTYPE TS&gt;
94&lt;TS version=&quot;2.1&quot; language=&quot;fr_FR&quot;&gt;
95&lt;context&gt;
96    &lt;name&gt;silly&lt;/name&gt;
97    &lt;message&gt;
98        &lt;location filename=&quot;../silly.qml&quot; line=&quot;11&quot;/&gt;
99        &lt;source&gt;Hello&lt;/source&gt;
100        &lt;translation&gt;Bonjour&lt;/translation&gt;
101    &lt;/message&gt;
102&lt;/context&gt;
103&lt;/TS&gt;
104&lt;RCC&gt;
105    &lt;qresource prefix=&quot;/qml/i18n&quot;&gt;
106        &lt;file&gt;qml_de.qm&lt;/file&gt;
107        &lt;file&gt;qml_en.qm&lt;/file&gt;
108        &lt;file&gt;qml_fr.qm&lt;/file&gt;
109    &lt;/qresource&gt;
110&lt;/RCC&gt;
111configure_file(cmake_qm_files.qrc ${CMAKE_BINARY_DIR} COPYONLY)
112add_executable(silly main.cpp
113    ${QRC_RESOURCES}
114    ${CMAKE_BINARY_DIR}/cmake_qm_files.qrc
115)
116

I typically use QLocale for translation testing as follows:

1├── CMakeLists.txt
2└── src
3    ├── CMakeLists.txt
4    ├── main.cpp
5    ├── silly.qrc
6    └── qml
7        ├── silly.qml
8        └── translations
9            ├── qml_de.ts
10            ├── qml_en.ts
11            └── qml_fr.ts
12cmake_minimum_required(VERSION 3.22)
13project(silly VERSION 1.0.0)
14add_subdirectory(src)
15cmake_minimum_required(VERSION 3.22)
16find_package(Qt5 COMPONENTS Qml Quick LinguistTools REQUIRED)
17set(TRANSLATIONS 
18    qml/translations/qml_en.ts
19    qml/translations/qml_fr.ts
20    qml/translations/qml_de.ts
21)
22qt5_create_translation(QM_FILES ${CMAKE_CURRENT_SOURCE_DIR} ${TRANSLATIONS})
23qt5_add_resources(QRC_RESOURCES &quot;silly.qrc&quot;) 
24
25add_executable(silly main.cpp 
26    &quot;${QRC_RESOURCES}&quot;
27    &quot;${QM_FILES}&quot;
28)
29target_compile_features(silly PUBLIC cxx_std_17)
30set_target_properties(silly PROPERTIES AUTOMOC ON AUTORCC ON)
31target_link_libraries(silly PRIVATE Qt5::Quick Qt5::Qml)
32target_include_directories(silly
33    PUBLIC
34        $&lt;INSTALL_INTERFACE:.&gt;
35        $&lt;BUILD_INTERFACE:${CMAKE_BINARY_DIR}&gt;
36)
37install(TARGETS silly)
38#include &lt;QGuiApplication&gt;
39#include &lt;QQmlApplicationEngine&gt;
40
41int main(int argc, char *argv[])
42{
43    QGuiApplication app(argc, argv);
44    QQmlApplicationEngine engine;
45    engine.addImportPath(&quot;qrc:/&quot;);
46    engine.load(QUrl(&quot;qrc:/qml/silly.qml&quot;));
47
48    return app.exec();
49}
50&lt;!DOCTYPE RCC&gt;&lt;RCC version=&quot;1.0&quot;&gt;
51    &lt;qresource prefix=&quot;/qml&quot;&gt;
52        &lt;file alias=&quot;silly.qml&quot;&gt;qml/silly.qml&lt;/file&gt;
53    &lt;/qresource&gt;
54&lt;/RCC&gt;
55import QtQuick 2.15
56import QtQuick.Window 2.15
57import QtQuick.Controls 2.15
58
59ApplicationWindow {
60    visible: true
61
62    Button {
63        anchors.fill: parent
64        spacing: 20
65        text: qsTr(&quot;Hello&quot;)
66    }
67}
68&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
69&lt;!DOCTYPE TS&gt;
70&lt;TS version=&quot;2.1&quot; language=&quot;de_DE&quot;&gt;
71&lt;context&gt;
72    &lt;name&gt;silly&lt;/name&gt;
73    &lt;message&gt;
74        &lt;location filename=&quot;../silly.qml&quot; line=&quot;11&quot;/&gt;
75        &lt;source&gt;Hello&lt;/source&gt;
76        &lt;translation&gt;Hallo&lt;/translation&gt;
77    &lt;/message&gt;
78&lt;/context&gt;
79&lt;/TS&gt;
80&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
81&lt;!DOCTYPE TS&gt;
82&lt;TS version=&quot;2.1&quot; language=&quot;en_US&quot;&gt;
83&lt;context&gt;
84    &lt;name&gt;silly&lt;/name&gt;
85    &lt;message&gt;
86        &lt;location filename=&quot;../silly.qml&quot; line=&quot;11&quot;/&gt;
87        &lt;source&gt;Hello&lt;/source&gt;
88        &lt;translation type=&quot;unfinished&quot;&gt;&lt;/translation&gt;
89    &lt;/message&gt;
90&lt;/context&gt;
91&lt;/TS&gt;
92&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
93&lt;!DOCTYPE TS&gt;
94&lt;TS version=&quot;2.1&quot; language=&quot;fr_FR&quot;&gt;
95&lt;context&gt;
96    &lt;name&gt;silly&lt;/name&gt;
97    &lt;message&gt;
98        &lt;location filename=&quot;../silly.qml&quot; line=&quot;11&quot;/&gt;
99        &lt;source&gt;Hello&lt;/source&gt;
100        &lt;translation&gt;Bonjour&lt;/translation&gt;
101    &lt;/message&gt;
102&lt;/context&gt;
103&lt;/TS&gt;
104&lt;RCC&gt;
105    &lt;qresource prefix=&quot;/qml/i18n&quot;&gt;
106        &lt;file&gt;qml_de.qm&lt;/file&gt;
107        &lt;file&gt;qml_en.qm&lt;/file&gt;
108        &lt;file&gt;qml_fr.qm&lt;/file&gt;
109    &lt;/qresource&gt;
110&lt;/RCC&gt;
111configure_file(cmake_qm_files.qrc ${CMAKE_BINARY_DIR} COPYONLY)
112add_executable(silly main.cpp
113    ${QRC_RESOURCES}
114    ${CMAKE_BINARY_DIR}/cmake_qm_files.qrc
115)
116QGuiApplication app(argc, argv);
117
118QLocale systemLocale = QLocale::system();
119QLocale::Language language = systemLocale.language();
120QLocale::Country country = systemLocale.country();
121qDebug() &lt;&lt; &quot;System locale language:&quot; &lt;&lt; language &lt;&lt; &quot;, country:&quot; &lt;&lt; country;
122
123// TEST: change default locale by removing comments below
124// language = QLocale::French;
125// country = QLocale::France;
126language = QLocale::English;
127country = QLocale::Australia;
128QLocale locale(language, country);
129qDebug() &lt;&lt; &quot;Changing default locale to language:&quot; &lt;&lt; locale.language() &lt;&lt; &quot;, country:&quot; &lt;&lt; locale.country();
130QLocale::setDefault(locale); // TEST: set default locale to something else than system locale
131
132QQmlApplicationEngine engine;
133

Source https://stackoverflow.com/questions/71672073

QUESTION

Combining Qt with OpenGL: does not compile

Asked 2022-Mar-19 at 21:50

I'm trying to create a project in Qt with an QOpenGLWidget and CMake as a building tool. The problem is that it does not compile and I don't know why.

1[...]\include\ui_MainWindow.h:79: błąd: undefined reference to `__imp__ZN13QOpenGLWidgetC1EP7QWidget6QFlagsIN2Qt10WindowTypeEE'
2

That's my CMakeLists.txt file:

1[...]\include\ui_MainWindow.h:79: błąd: undefined reference to `__imp__ZN13QOpenGLWidgetC1EP7QWidget6QFlagsIN2Qt10WindowTypeEE'
2cmake_minimum_required(VERSION 3.5)
3
4project(QtTest VERSION 0.1 LANGUAGES CXX)
5
6set(CMAKE_INCLUDE_CURRENT_DIR ON)
7
8set(CMAKE_AUTOUIC ON)
9set(CMAKE_AUTOMOC ON)
10set(CMAKE_AUTORCC ON)
11
12set(CMAKE_CXX_STANDARD 11)
13set(CMAKE_CXX_STANDARD_REQUIRED ON)
14
15find_package(OpenGL REQUIRED)
16find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets REQUIRED)
17find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets REQUIRED)
18find_package(Qt${QT_VERSION_MAJOR} COMPONENTS OpenGL REQUIRED)
19
20set(PROJECT_SOURCES
21        src/main.cpp
22        src/MainWindow.cpp
23        src/MainWindow.hpp
24        src/MainWindow.ui
25)
26
27if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
28    qt_add_executable(QtTest
29        MANUAL_FINALIZATION
30        ${PROJECT_SOURCES}
31    )
32else()
33    add_executable(QtTest
34        ${PROJECT_SOURCES}
35    )
36endif()
37
38target_link_libraries(QtTest PRIVATE Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::OpenGL)
39
40set_target_properties(QtTest PROPERTIES
41    MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com
42    MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
43    MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
44    MACOSX_BUNDLE TRUE
45    WIN32_EXECUTABLE TRUE
46)
47
48if(QT_VERSION_MAJOR EQUAL 6)
49    qt_finalize_executable(QtTest)
50endif()
51

In my MainWindow.ui file I only create an QOpenGLWidget widget.

ANSWER

Answered 2022-Mar-19 at 21:50

In Qt6 QOpenGLWidget was moved to a new module named OpenGLWidgets. To make your program work you need to add OpenGLWidgets to your find_package command and Qt6::OpenGLWidgets to your target_link_libraries command.

1[...]\include\ui_MainWindow.h:79: błąd: undefined reference to `__imp__ZN13QOpenGLWidgetC1EP7QWidget6QFlagsIN2Qt10WindowTypeEE'
2cmake_minimum_required(VERSION 3.5)
3
4project(QtTest VERSION 0.1 LANGUAGES CXX)
5
6set(CMAKE_INCLUDE_CURRENT_DIR ON)
7
8set(CMAKE_AUTOUIC ON)
9set(CMAKE_AUTOMOC ON)
10set(CMAKE_AUTORCC ON)
11
12set(CMAKE_CXX_STANDARD 11)
13set(CMAKE_CXX_STANDARD_REQUIRED ON)
14
15find_package(OpenGL REQUIRED)
16find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets REQUIRED)
17find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets REQUIRED)
18find_package(Qt${QT_VERSION_MAJOR} COMPONENTS OpenGL REQUIRED)
19
20set(PROJECT_SOURCES
21        src/main.cpp
22        src/MainWindow.cpp
23        src/MainWindow.hpp
24        src/MainWindow.ui
25)
26
27if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
28    qt_add_executable(QtTest
29        MANUAL_FINALIZATION
30        ${PROJECT_SOURCES}
31    )
32else()
33    add_executable(QtTest
34        ${PROJECT_SOURCES}
35    )
36endif()
37
38target_link_libraries(QtTest PRIVATE Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::OpenGL)
39
40set_target_properties(QtTest PROPERTIES
41    MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com
42    MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
43    MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
44    MACOSX_BUNDLE TRUE
45    WIN32_EXECUTABLE TRUE
46)
47
48if(QT_VERSION_MAJOR EQUAL 6)
49    qt_finalize_executable(QtTest)
50endif()
51find_package(Qt6 COMPONENTS Widgets OpenGL OpenGLWidgets REQUIRED)
52target_link_libraries(QtTest PRIVATE Qt6::Widgets Qt6::OpenGL Qt6::OpenGLWidgets)
53

Source https://stackoverflow.com/questions/71539895

QUESTION

Qt 5 Disabling Click-and-Hold

Asked 2022-Mar-17 at 08:29

I'm trying to solve an issue in a Qt5 application that's caused by a touchscreen driver I wrote a couple years ago. The problem being that my touchscreen driver generates mouse press events to simulate touch behavior. This was because at the time I wrote it, my team was using an outdated Linux OS that didn't have a native touch driver.

The problem is that when I touch the +/- buttons (the scroll buttons that increase/decrease the slider by a single tick, or cause it to rapidly scroll if held), the slider rapidly slides up/down as if I had clicked and held the button. This is because my driver uses QApplication::postEvent() to dispatch the mouse event from a separate thread, and the delay in between touch and release is just long enough for it to register a click-and-hold type event, though the release event doesn't stop the sliding.

I would rewrite the application to use the now available native touch driver, but it doesn't offer enough control to be able to do what my driver does (my driver can generate left, right, or middle mouse events, whereas the native driver only provides left).

I tried rewriting the driver to use QApplication::sendEvent() instead, but that was causing a segmentation fault that I couldn't figure out the cause of.

So is there a way I can disable the "click-and-hold" type behavior on the QSlider itself? So that I can still tap the buttons, but they'll only increase/decrease by a single tick at a time?

EDIT: Here's an example of how I'm generating the "touch" events via my driver.

1void InputHandler::touchPress(TouchPoint * tp, QWidget * widget) {
2    QPoint screenPos(tp-&gt;cx(), tp-&gt;cy());
3    QWidget * target = widget;
4    if(target == NULL) target = QApplication::widgetAt(screenPos);
5
6    if(target != NULL) {
7        QPoint local = target-&gt;mapFromGlobal(screenPos);
8        QMouseEvent * press = new QMouseEvent(QEvent::MouseButtonPress, local, screenPos, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
9        QApplication::postEvent(target, press);
10
11        DBG(&quot; -- touch press on: &quot; &lt;&lt; typeid(*widget).name());
12
13        // Check to see if the target is a QLineEdit or QComboBox, and if so, set focus on it.
14        QLineEdit * lineEdit = dynamic_cast&lt;QLineEdit*&gt;(target);
15        QComboBox * comboBox = dynamic_cast&lt;QComboBox*&gt;(target);
16        if(lineEdit) lineEdit-&gt;setFocus(Qt::MouseFocusReason);
17        if(comboBox) comboBox-&gt;setFocus(Qt::MouseFocusReason);
18    }
19}
20

EDIT 2: So a coworker played around with the slider and pointed out that he pressed the +/- buttons, causing it to slide, and then he clicks the "reset" button we have to reset all controls on the form, the slider would reset and then continue sliding, indicating that the touch press was never released. He then would click the +/- buttons normally with the mouse and reset again and it would stop. So even though the logs indicate that the mousePressEvent and mouseReleaseEvent methods are being triggered by my events, they don't seem to have the same behavior as using the mouse.

Any ideas?

EDIT 3: If it helps, I added an eventFilter and printed out every event type that the QSlider receives, from when I first touch the screen to when I release. The events received are:

1void InputHandler::touchPress(TouchPoint * tp, QWidget * widget) {
2    QPoint screenPos(tp-&gt;cx(), tp-&gt;cy());
3    QWidget * target = widget;
4    if(target == NULL) target = QApplication::widgetAt(screenPos);
5
6    if(target != NULL) {
7        QPoint local = target-&gt;mapFromGlobal(screenPos);
8        QMouseEvent * press = new QMouseEvent(QEvent::MouseButtonPress, local, screenPos, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
9        QApplication::postEvent(target, press);
10
11        DBG(&quot; -- touch press on: &quot; &lt;&lt; typeid(*widget).name());
12
13        // Check to see if the target is a QLineEdit or QComboBox, and if so, set focus on it.
14        QLineEdit * lineEdit = dynamic_cast&lt;QLineEdit*&gt;(target);
15        QComboBox * comboBox = dynamic_cast&lt;QComboBox*&gt;(target);
16        if(lineEdit) lineEdit-&gt;setFocus(Qt::MouseFocusReason);
17        if(comboBox) comboBox-&gt;setFocus(Qt::MouseFocusReason);
18    }
19}
20Mouse Press (2)
21Tooltip Change (184)
22Paint (12)
23Mouse Move (5)
24Mouse Move (5)
25Mouse Release (3)
26

But then after the release event, I get spammed in the logs with QEvent::Timer events, which does not happen when I simply click with the mouse, as opposed to touching the slider with the touchscreen. If I then tap somewhere else, drag the slider, or click the slider with the actual mouse, these timer events stop.

Why is my generated QMouseEvent causing these QEvent::Timer events to be generated when I tap the slider with the touchscreen, but not with the mouse?

ANSWER

Answered 2022-Mar-17 at 08:29

A minimal example to generate mouse press/release events that are correctly handled by QSlider is:

1void InputHandler::touchPress(TouchPoint * tp, QWidget * widget) {
2    QPoint screenPos(tp-&gt;cx(), tp-&gt;cy());
3    QWidget * target = widget;
4    if(target == NULL) target = QApplication::widgetAt(screenPos);
5
6    if(target != NULL) {
7        QPoint local = target-&gt;mapFromGlobal(screenPos);
8        QMouseEvent * press = new QMouseEvent(QEvent::MouseButtonPress, local, screenPos, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
9        QApplication::postEvent(target, press);
10
11        DBG(&quot; -- touch press on: &quot; &lt;&lt; typeid(*widget).name());
12
13        // Check to see if the target is a QLineEdit or QComboBox, and if so, set focus on it.
14        QLineEdit * lineEdit = dynamic_cast&lt;QLineEdit*&gt;(target);
15        QComboBox * comboBox = dynamic_cast&lt;QComboBox*&gt;(target);
16        if(lineEdit) lineEdit-&gt;setFocus(Qt::MouseFocusReason);
17        if(comboBox) comboBox-&gt;setFocus(Qt::MouseFocusReason);
18    }
19}
20Mouse Press (2)
21Tooltip Change (184)
22Paint (12)
23Mouse Move (5)
24Mouse Move (5)
25Mouse Release (3)
26#include &lt;QApplication&gt;
27#include &lt;QMainWindow&gt;
28#include &lt;QMouseEvent&gt;
29#include &lt;QSlider&gt;
30#include &lt;QTimer&gt;
31
32int main(int argc, char *argv[])
33{
34    QApplication a(argc, argv);
35
36    QMainWindow m;
37    QSlider *slider = new QSlider();
38    m.setCentralWidget(slider);
39    m.resize(100, 100);
40    m.show();
41
42    QTimer::singleShot(1000, [&amp;](){
43        a.postEvent(slider, new QMouseEvent(QEvent::MouseButtonPress, QPoint(50,50), m.mapToGlobal(QPoint(50,50)), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier));
44        a.postEvent(slider, new QMouseEvent(QEvent::MouseButtonRelease, QPoint(50,50), m.mapToGlobal(QPoint(50,50)), Qt::LeftButton, Qt::NoButton, Qt::NoModifier));
45    });
46
47    return a.exec();
48}
49

This example decreases the slider value with 1 tick after 1 second.

Note that it is important to pass Qt::NoButton as buttons parameters to the QEvent::MouseButtonRelease event, otherwise the slider will continue moving to the current mouse position (see QAbstractSlider::setRepeatAction), as QSlider thinks the button is still pressed. I assume this behaviour is what you call 'press-and-hold'.

Source https://stackoverflow.com/questions/71382216

QUESTION

Does QtNetworkAuth support PKCE

Asked 2022-Mar-16 at 08:26

I use Qt5. I did not find any documentation on how to enable PKCE when using QOAuth2AuthorizationCodeFlow.

If so, please provide the link. If there is no support, how can this feature be added to it?

I added code_challenge and code_challenge_method, but it is not enough. I don't know what the next step is.

1#include &lt;QtNetworkAuth/QtNetworkAuth&gt;
2
3void loginHelper()
4{
5   auto* authFlow = new QOAuth2AuthorizationCodeFlow;
6   QObject::connect(authFlow, &amp;QOAuth2AuthorizationCodeFlow::authorizeWithBrowser, &amp;QDesktopServices::openUrl);
7   authFlow-&gt;setScope(&quot;openid profile email mobile&quot;);
8   authFlow-&gt;setAuthorizationUrl(QUrl(&quot;https://accounts.XYZ.com/core/connect/authorize&quot;)); // url is changed
9   authFlow-&gt;setClientIdentifier(&quot;desktop.test&quot;);
10   authFlow-&gt;setAccessTokenUrl(QUrl(&quot;https://accounts.XYZ.com/core/connect/token&quot;)); // url is changed
11   authFlow-&gt;setClientIdentifierSharedKey(&quot;0323af0d-efe2-fcec-b450-72f102530a77&quot;);
12   authFlow-&gt;setModifyParametersFunction([=](QAbstractOAuth::Stage, QVariantMap* params)
13      {
14         params-&gt;insert(&quot;code_challenge&quot;, &quot;1Kht0Wkyt_WvDngoM_AIOYPPOWG8lzVG1g1zk28TjSo&quot;);
15         params-&gt;insert(&quot;code_challenge_method&quot;, &quot;S256&quot;);
16      });
17   auto* replyHandler = new QOAuthHttpServerReplyHandler(1234); // port number
18   authFlow-&gt;setReplyHandler(replyHandler);
19   QObject::connect(authFlow, &amp;QOAuth2AuthorizationCodeFlow::granted, []()
20      {
21         qDebug() &lt;&lt; &quot;Access Granted!&quot;;
22      });
23   authFlow-&gt;grant();
24}
25

ANSWER

Answered 2022-Mar-15 at 12:34

TL;DR Yes, and you are using it.

Reading the new flow you notice there are three new parameters used by PKCE, code_verifier, code_challenge and code_challenge_method.

These are used in your code, so you are using PKCE already.

Source https://stackoverflow.com/questions/71480646

QUESTION

Changing QThread variable from a sub window

Asked 2022-Mar-08 at 18:46

I am writing a WebCam Gui, which is supposed to take pictures and manipulate with WebCam parameters. After the video stream is activated on the main GUI window, an additional window can be opened to change the WebCamera parameters Screenshot 1, Screenshot 2.

I am using Qthread to stream on QLabel. Also, I was able to set the initial camera parameters on the camera properties' changing window. My problem is changing the Exposure parameter by using a slider on the sub-window and seeing results in real-time on the main window.

Please see the code.

1import sys
2from PyQt5.QtWidgets import *
3from PyQt5 import uic
4from PyQt5.QtCore import *
5from PyQt5.QtGui import *
6import cv2
7
8
9class MainFrame(QMainWindow):
10
11    def __init__(self):
12        super(MainFrame, self).__init__()
13        # Loading UI
14    
15        uic.loadUi(&quot;MainFrame.ui&quot;, self)
16    
17        # Remove maximize button to prevent crushing
18        self.setWindowFlags(Qt.WindowCloseButtonHint | Qt.WindowMinimizeButtonHint)
19    
20        # Define Widgets
21        self.Video_Feed = self.findChild(QLabel, 'Video_Feed')
22        self.Case_Name = self.findChild(QLineEdit, &quot;Case_Name&quot;)
23        self.Pictures_List = self.findChild(QListWidget, &quot;Pictures_List&quot;)
24        self.Start_Video = self.findChild(QAction, 'actionStart_Video')
25        self.Start_Video.setShortcut('Shift+S')
26        self.Stop_Video = self.findChild(QAction, 'actionStop_Video')
27        self.Stop_Video.setShortcut('Shift+F')
28        self.Take_a_Picture = self.findChild(QAction, 'actionTake_a_picture')
29        self.Take_a_Timed_Picture = self.findChild(QAction, 'actionTake_a_timed_picture')
30        self.Camera_Properties = self.findChild(QAction, 'actionProperties')
31    
32        # Initializing Video
33        self.Start_Video.triggered.connect(self.Start_Video_Clicked)
34        self.Stop_Video.triggered.connect(self.Stop_Video_Clicked)
35        self.Camera_Properties.triggered.connect(self.Camera_Properties_Clicked)
36    
37    def Video_Feed_Update(self, Image):
38        self.Video_Feed.setPixmap(QPixmap.fromImage(Image))
39    
40    def Start_Video_Clicked(self):
41        self.Video_Feed_is_Running = True
42        self.thread = QThread()
43        self.Video_Thread = Worker()
44        self.Video_Thread.moveToThread(self.thread)
45        self.Video_Thread.ImageUpdate.connect(self.Video_Feed_Update)
46        self.thread.started.connect(self.Video_Thread.run)
47        self.thread.start()
48    
49    def Stop_Video_Clicked(self):
50        self.Video_Thread.stop_video()
51        self.Video_Feed.setText(&quot;Your video starts here&quot;)
52    
53    def Camera_Properties_Clicked(self):
54        self.CP = CameraParameters()
55        Initial_Exposure = self.Video_Thread.Camera_Initial_Parameters()
56        self.CP.Setup_Exposure(int(Initial_Exposure))
57        self.CP.Exposure_Calibration.connect(self.Video_Thread.Exposure_update)
58        self.CP.show()
59
60
61class Worker(QObject):
62    ImageUpdate = pyqtSignal(QImage)
63
64    def run(self):
65        self.ThreadActive = True
66        self.Capture = cv2.VideoCapture(1, cv2.CAP_DSHOW)
67        self.Capture.set(3, 1920)
68        self.Capture.set(4, 1080)
69        while self.ThreadActive:
70            ret, frame = self.Capture.read()
71            if ret:
72                image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
73                # Converting Video into QT5 readable format
74                qt_video_format = QImage(image.data, image.shape[1], image.shape[0], QImage.Format_RGB888)
75                qt_picture = qt_video_format.scaled(1280, 720, Qt.KeepAspectRatio)
76                self.ImageUpdate.emit(qt_picture)
77    
78    def stop_video(self):
79        self.ThreadActive = False
80        self.Capture.release()
81    
82    def Camera_Initial_Parameters(self):
83        return self.Capture.get(cv2.CAP_PROP_EXPOSURE)
84    
85    def Exposure_update(self, value):
86        self.Capture.set(cv2.CAP_PROP_EXPOSURE, value)
87
88
89class CameraParameters(QDialog):
90    Exposure_Calibration = pyqtSignal(int)
91    
92    def __init__(self):
93        super().__init__()
94        uic.loadUi('Cam_Parameters.ui', self)
95    
96        # Sliders
97        self.Exposure_Slider = self.findChild(QSlider, 'ExposureSlider')
98        self.Exposure_Slider.setRange(-10, 10)
99        self.White_Balance_Slider = self.findChild(QSlider, 'WBSlider')
100        self.White_Balance_Slider.setMinimum(-10)
101        self.White_Balance_Slider.setMaximum(10)
102        self.Brightness_Slider = self.findChild(QSlider, 'BrightnessSlider')
103        self.Brightness_Slider.setMinimum(0)
104        self.Brightness_Slider.setMaximum(300)
105        self.Saturation_Slider = self.findChild(QSlider, 'SaturationSlider')
106        self.Saturation_Slider.setMinimum(0)
107        self.Saturation_Slider.setMaximum(300)
108        self.Contrast_Slider = self.findChild(QSlider, 'ContrastSlider')
109        self.Contrast_Slider.setMinimum(-10)
110        self.Contrast_Slider.setMaximum(10)
111        self.Gamma_Slider = self.findChild(QSlider, 'GammaSlider')
112        self.Gamma_Slider.setMinimum(-10)
113        self.Gamma_Slider.setMaximum(10)
114        self.Sharpness_Slider = self.findChild(QSlider, 'SharpnessSlider')
115        self.Sharpness_Slider.setMinimum(0)
116        self.Sharpness_Slider.setMaximum(100)
117        # Sliders values
118        self.Exposure_Value = self.findChild(QLabel, 'Exposure_Value')
119        self.White_Balance_Value = self.findChild(QLabel, 'WB_value')
120        self.Brightness_Value = self.findChild(QLabel, 'Brightness_value')
121        self.Saturation_Value = self.findChild(QLabel, 'Saturation_value')
122        self.Contrast_Value = self.findChild(QLabel, 'Contrast_value')
123        self.Gamma_Value = self.findChild(QLabel, 'Gamma_value')
124        self.Sharpness_Value = self.findChild(QLabel, 'Sharpness_value')
125    
126        # Connections
127        self.Exposure_Slider.valueChanged.connect(self.Exposure_sliding)
128    
129    def Setup_Exposure(self, value):
130        self.Exposure_Slider.setValue(value)
131        self.Exposure_Value.setText(str(value))
132    
133    def Exposure_sliding(self, value):
134        self.Exposure_Value.setText(str(value))
135        self.Exposure_Calibration.emit(value)
136
137
138if __name__ == &quot;__main__&quot;:
139    App = QApplication(sys.argv)
140    Root = MainFrame()
141    Root.show()
142    sys.exit(App.exec())
143
144

ANSWER

Answered 2022-Mar-07 at 17:05

I admit I don't know why this worked, but changing the connect to a lambda function did the trick.

1import sys
2from PyQt5.QtWidgets import *
3from PyQt5 import uic
4from PyQt5.QtCore import *
5from PyQt5.QtGui import *
6import cv2
7
8
9class MainFrame(QMainWindow):
10
11    def __init__(self):
12        super(MainFrame, self).__init__()
13        # Loading UI
14    
15        uic.loadUi(&quot;MainFrame.ui&quot;, self)
16    
17        # Remove maximize button to prevent crushing
18        self.setWindowFlags(Qt.WindowCloseButtonHint | Qt.WindowMinimizeButtonHint)
19    
20        # Define Widgets
21        self.Video_Feed = self.findChild(QLabel, 'Video_Feed')
22        self.Case_Name = self.findChild(QLineEdit, &quot;Case_Name&quot;)
23        self.Pictures_List = self.findChild(QListWidget, &quot;Pictures_List&quot;)
24        self.Start_Video = self.findChild(QAction, 'actionStart_Video')
25        self.Start_Video.setShortcut('Shift+S')
26        self.Stop_Video = self.findChild(QAction, 'actionStop_Video')
27        self.Stop_Video.setShortcut('Shift+F')
28        self.Take_a_Picture = self.findChild(QAction, 'actionTake_a_picture')
29        self.Take_a_Timed_Picture = self.findChild(QAction, 'actionTake_a_timed_picture')
30        self.Camera_Properties = self.findChild(QAction, 'actionProperties')
31    
32        # Initializing Video
33        self.Start_Video.triggered.connect(self.Start_Video_Clicked)
34        self.Stop_Video.triggered.connect(self.Stop_Video_Clicked)
35        self.Camera_Properties.triggered.connect(self.Camera_Properties_Clicked)
36    
37    def Video_Feed_Update(self, Image):
38        self.Video_Feed.setPixmap(QPixmap.fromImage(Image))
39    
40    def Start_Video_Clicked(self):
41        self.Video_Feed_is_Running = True
42        self.thread = QThread()
43        self.Video_Thread = Worker()
44        self.Video_Thread.moveToThread(self.thread)
45        self.Video_Thread.ImageUpdate.connect(self.Video_Feed_Update)
46        self.thread.started.connect(self.Video_Thread.run)
47        self.thread.start()
48    
49    def Stop_Video_Clicked(self):
50        self.Video_Thread.stop_video()
51        self.Video_Feed.setText(&quot;Your video starts here&quot;)
52    
53    def Camera_Properties_Clicked(self):
54        self.CP = CameraParameters()
55        Initial_Exposure = self.Video_Thread.Camera_Initial_Parameters()
56        self.CP.Setup_Exposure(int(Initial_Exposure))
57        self.CP.Exposure_Calibration.connect(self.Video_Thread.Exposure_update)
58        self.CP.show()
59
60
61class Worker(QObject):
62    ImageUpdate = pyqtSignal(QImage)
63
64    def run(self):
65        self.ThreadActive = True
66        self.Capture = cv2.VideoCapture(1, cv2.CAP_DSHOW)
67        self.Capture.set(3, 1920)
68        self.Capture.set(4, 1080)
69        while self.ThreadActive:
70            ret, frame = self.Capture.read()
71            if ret:
72                image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
73                # Converting Video into QT5 readable format
74                qt_video_format = QImage(image.data, image.shape[1], image.shape[0], QImage.Format_RGB888)
75                qt_picture = qt_video_format.scaled(1280, 720, Qt.KeepAspectRatio)
76                self.ImageUpdate.emit(qt_picture)
77    
78    def stop_video(self):
79        self.ThreadActive = False
80        self.Capture.release()
81    
82    def Camera_Initial_Parameters(self):
83        return self.Capture.get(cv2.CAP_PROP_EXPOSURE)
84    
85    def Exposure_update(self, value):
86        self.Capture.set(cv2.CAP_PROP_EXPOSURE, value)
87
88
89class CameraParameters(QDialog):
90    Exposure_Calibration = pyqtSignal(int)
91    
92    def __init__(self):
93        super().__init__()
94        uic.loadUi('Cam_Parameters.ui', self)
95    
96        # Sliders
97        self.Exposure_Slider = self.findChild(QSlider, 'ExposureSlider')
98        self.Exposure_Slider.setRange(-10, 10)
99        self.White_Balance_Slider = self.findChild(QSlider, 'WBSlider')
100        self.White_Balance_Slider.setMinimum(-10)
101        self.White_Balance_Slider.setMaximum(10)
102        self.Brightness_Slider = self.findChild(QSlider, 'BrightnessSlider')
103        self.Brightness_Slider.setMinimum(0)
104        self.Brightness_Slider.setMaximum(300)
105        self.Saturation_Slider = self.findChild(QSlider, 'SaturationSlider')
106        self.Saturation_Slider.setMinimum(0)
107        self.Saturation_Slider.setMaximum(300)
108        self.Contrast_Slider = self.findChild(QSlider, 'ContrastSlider')
109        self.Contrast_Slider.setMinimum(-10)
110        self.Contrast_Slider.setMaximum(10)
111        self.Gamma_Slider = self.findChild(QSlider, 'GammaSlider')
112        self.Gamma_Slider.setMinimum(-10)
113        self.Gamma_Slider.setMaximum(10)
114        self.Sharpness_Slider = self.findChild(QSlider, 'SharpnessSlider')
115        self.Sharpness_Slider.setMinimum(0)
116        self.Sharpness_Slider.setMaximum(100)
117        # Sliders values
118        self.Exposure_Value = self.findChild(QLabel, 'Exposure_Value')
119        self.White_Balance_Value = self.findChild(QLabel, 'WB_value')
120        self.Brightness_Value = self.findChild(QLabel, 'Brightness_value')
121        self.Saturation_Value = self.findChild(QLabel, 'Saturation_value')
122        self.Contrast_Value = self.findChild(QLabel, 'Contrast_value')
123        self.Gamma_Value = self.findChild(QLabel, 'Gamma_value')
124        self.Sharpness_Value = self.findChild(QLabel, 'Sharpness_value')
125    
126        # Connections
127        self.Exposure_Slider.valueChanged.connect(self.Exposure_sliding)
128    
129    def Setup_Exposure(self, value):
130        self.Exposure_Slider.setValue(value)
131        self.Exposure_Value.setText(str(value))
132    
133    def Exposure_sliding(self, value):
134        self.Exposure_Value.setText(str(value))
135        self.Exposure_Calibration.emit(value)
136
137
138if __name__ == &quot;__main__&quot;:
139    App = QApplication(sys.argv)
140    Root = MainFrame()
141    Root.show()
142    sys.exit(App.exec())
143
144self.CP.Exposure_Calibration.connect(lambda x: self.Video_Thread.Exposure_update(x))
145

Source https://stackoverflow.com/questions/71368379

QUESTION

Is there a way to access QMainWindowPrivate or QMainWindowLayout?

Asked 2022-Feb-27 at 14:43

I'm using Qt5 and I am trying to do this:

1setCentralWidget(wid);
2...
3setCentralWidget(nullptr); // i don't want it to do deleteLater() for my wid variable
4...
5setCentralWidget(wid);
6

The problem is that, when I call setCentralWidget(nullptr), it does deleteLater() for my wid variable.

So, I found a way to use setCentralWidget() without deleting the wid variable:

1setCentralWidget(wid);
2...
3setCentralWidget(nullptr); // i don't want it to do deleteLater() for my wid variable
4...
5setCentralWidget(wid);
6Q_D(QMainWindow);
7d-&gt;layout-&gt;setCentralWidget(nullptr);
8

But the question is: How to use private headers or widgets or whatever? I mean, I don't have access to QMainWindowPrivate or QMainWindowLayout, because they are private. So is there a way to access them?

ANSWER

Answered 2022-Feb-27 at 13:32

OP's issue is caused by using setCentralWidget(nullptr);.

QMainWindow::setCentralWiget():

Sets the given widget to be the main window's central widget.

Note: QMainWindow takes ownership of the widget pointer and deletes it at the appropriate time.

(Emphasis mine.)

Hence, for

1setCentralWidget(wid);
2...
3setCentralWidget(nullptr); // i don't want it to do deleteLater() for my wid variable
4...
5setCentralWidget(wid);
6Q_D(QMainWindow);
7d-&gt;layout-&gt;setCentralWidget(nullptr);
8setCentralWidget(wid);
9...
10setCentralWidget(nullptr);
11

it has to be expected that the QMainWindow will delete the wid. Otherwise, the wid instance could become orphaned i.e. a memory leak.

However, OPs issue can be solved without adventurous accesses to internals of QMainWindow (which is neither intended nor necessary).

In fact, there is an alternative to remove the central widget and take over the ownership again – QMainWindow::takeCentralWidget():

Removes the central widget from this main window.

The ownership of the removed widget is passed to the caller.

(Emphasis mine, again.)

An MCVE to demonstrate this:

1setCentralWidget(wid);
2...
3setCentralWidget(nullptr); // i don't want it to do deleteLater() for my wid variable
4...
5setCentralWidget(wid);
6Q_D(QMainWindow);
7d-&gt;layout-&gt;setCentralWidget(nullptr);
8setCentralWidget(wid);
9...
10setCentralWidget(nullptr);
11#include &lt;QtWidgets&gt;
12
13// main application
14
15int main(int argc, char **argv)
16{
17  qDebug() &lt;&lt; &quot;Qt Version:&quot; &lt;&lt; QT_VERSION_STR;
18  QApplication app(argc, argv);
19  // setup GUI
20  QMainWindow qWinMain;
21  qWinMain.setWindowTitle(&quot;QMainWindow::takeCentralWidget&quot;);
22  QLabel *pQLbl = new QLabel(&quot;The\ncentral\nwidget&quot;);
23  pQLbl-&gt;setAlignment(Qt::AlignCenter);
24  qWinMain.setCentralWidget(pQLbl);
25  qWinMain.show();
26  QTimer qTimer;
27  qTimer.setInterval(1000);
28  uint n = 10;
29  // install signal handlers
30  QObject::connect(&amp;qTimer, &amp;QTimer::timeout,
31    [&amp;]() {
32      --n;
33      if (!n) {
34        qWinMain.setCentralWidget(nullptr);
35        app.quit();
36      } else if (n &amp; 1) qWinMain.setCentralWidget(pQLbl);
37      else qWinMain.takeCentralWidget();
38    });
39  // runtime loop
40  qTimer.start();
41  return app.exec();
42}
43

Output: Snapshot of testQMainWindow-takeCentralWidget

Source https://stackoverflow.com/questions/71284270

QUESTION

Build and run a Qt application on macOS via Bazel

Asked 2022-Feb-16 at 17:13

I tried to build and run a Qt5 (5.15.2) application on macOS (10.15.7) using Bazel 5.0.0. Unfortunately, I run into some problems. The building part seems to work, but not the run part.

I installed Qt5 on my machine using Homebrew:

1brew install qt@5
2brew link qt@5
3

I adapted https://github.com/justbuchanan/bazel_rules_qt/ to my needs. See this PR. When I try to run:

1brew install qt@5
2brew link qt@5
3bazel run --cxxopt=-std=c++17 //tests/qt_resource:main
4

I receive the runtime error:

1brew install qt@5
2brew link qt@5
3bazel run --cxxopt=-std=c++17 //tests/qt_resource:main
4dyld: Symbol not found: __ZN10QByteArray6_emptyE
5

Steps to reproduce the issue:

1brew install qt@5
2brew link qt@5
3bazel run --cxxopt=-std=c++17 //tests/qt_resource:main
4dyld: Symbol not found: __ZN10QByteArray6_emptyE
5# brew install bazel # Install Bazel
6# brew install qt@5  # Install Qt5
7git clone https://github.com/Vertexwahn/bazel_rules_qt.git
8cd bazel_rules_qt
9git checkout add-macos-support
10bazel build --cxxopt=-std=c++17 //... # should work
11bazel run --cxxopt=-std=c++17 //tests/qt_resource:main # should give you the error message
12

Nevertheless, building everything using bazel build --cxxopt=-std=c++17 //... seems to work. I am not 100% sure if the link options -F/usr/local/opt/qt5/Frameworks and -framework QtCore, etc. are correct. Maybe someone can confirm this.

Did I use the correct link options?

For me, it is a bit unclear what dependencies the main binary expects. I tried to copy QtCore.framework to the location of the main binary manually but this does not change the error message.

What files does the main binary expect?

If I try to run macdeployqt on my main binary I get also some errors. I do within my workspace root dir a cd bazel-bin/tests/qt_resource and run then /usr/local/opt/qt5/bin/macdeployqt main:

1brew install qt@5
2brew link qt@5
3bazel run --cxxopt=-std=c++17 //tests/qt_resource:main
4dyld: Symbol not found: __ZN10QByteArray6_emptyE
5# brew install bazel # Install Bazel
6# brew install qt@5  # Install Qt5
7git clone https://github.com/Vertexwahn/bazel_rules_qt.git
8cd bazel_rules_qt
9git checkout add-macos-support
10bazel build --cxxopt=-std=c++17 //... # should work
11bazel run --cxxopt=-std=c++17 //tests/qt_resource:main # should give you the error message
12ERROR: Could not find bundle binary for &quot;main&quot;
13ERROR: &quot;error: /Library/Developer/CommandLineTools/usr/bin/otool-classic: can't open file:  (No such file or directory)\n&quot;
14ERROR: &quot;error: /Library/Developer/CommandLineTools/usr/bin/otool-classic: can't open file:  (No such file or directory)\n&quot;
15ERROR: &quot;error: /Library/Developer/CommandLineTools/usr/bin/otool-classic: can't open file:  (No such file or directory)\n&quot;
16WARNING:
17WARNING: Could not find any external Qt frameworks to deploy in &quot;main&quot;
18WARNING: Perhaps macdeployqt was already used on &quot;main&quot; ?
19WARNING: If so, you will need to rebuild &quot;main&quot; before trying again.
20ERROR: Could not find bundle binary for &quot;main&quot;
21ERROR: &quot;error: /Library/Developer/CommandLineTools/usr/bin/strip: can't open file:  (No such file or directory)\n&quot;
22ERROR: &quot;&quot;
23

My hope was that macdeployqt would collect all needed resources for me. Any idea why this is not working?

How can macdeployqt be used to collect all needed dependencies for the main binary?

If I convert my main to an app via lipo -create -output universall_app main and do then a /usr/local/opt/qt5/bin/macdeployqt universall_app I get the same error message.

The CMake approach

To make sure that there is no general problem with my system setup I tried to use CMake to build a Qt5 application:

1brew install qt@5
2brew link qt@5
3bazel run --cxxopt=-std=c++17 //tests/qt_resource:main
4dyld: Symbol not found: __ZN10QByteArray6_emptyE
5# brew install bazel # Install Bazel
6# brew install qt@5  # Install Qt5
7git clone https://github.com/Vertexwahn/bazel_rules_qt.git
8cd bazel_rules_qt
9git checkout add-macos-support
10bazel build --cxxopt=-std=c++17 //... # should work
11bazel run --cxxopt=-std=c++17 //tests/qt_resource:main # should give you the error message
12ERROR: Could not find bundle binary for &quot;main&quot;
13ERROR: &quot;error: /Library/Developer/CommandLineTools/usr/bin/otool-classic: can't open file:  (No such file or directory)\n&quot;
14ERROR: &quot;error: /Library/Developer/CommandLineTools/usr/bin/otool-classic: can't open file:  (No such file or directory)\n&quot;
15ERROR: &quot;error: /Library/Developer/CommandLineTools/usr/bin/otool-classic: can't open file:  (No such file or directory)\n&quot;
16WARNING:
17WARNING: Could not find any external Qt frameworks to deploy in &quot;main&quot;
18WARNING: Perhaps macdeployqt was already used on &quot;main&quot; ?
19WARNING: If so, you will need to rebuild &quot;main&quot; before trying again.
20ERROR: Could not find bundle binary for &quot;main&quot;
21ERROR: &quot;error: /Library/Developer/CommandLineTools/usr/bin/strip: can't open file:  (No such file or directory)\n&quot;
22ERROR: &quot;&quot;
23git clone https://github.com/euler0/mini-cmake-qt.git
24cmake -DCMAKE_PREFIX_PATH=/usr/local/opt/qt5 .
25make -j
26

This produces an example.app. With a double click on this application bundle, the application can be started. This worked on my system.

Future directions

It seems that rules_apple can be used to create an application bundle. I am not sure if I need to transform my Qt application binary to an app bundle to be able to execute it. One could use --sandbox_debugto identify what Bazel is doing and dtruss for the CMake version to compare the differences. I am currently not sure what trying to do next and hope for an easy solution. I am also fine with a Qt6 solution.

Update: Alternative Answer

It would also be helpful if someone can point out how to build a minimal Qt application using make only on macOS and a brew installed Qt5 or tell me what the linker and compiler options must look like.

ANSWER

Answered 2022-Feb-16 at 17:13

I followed your steps with Mac OSX 10.15.7, Qt (installed by homebrew) 5.15.1 and both bazel 4.2.2-homebrew and 5.0.0-homebrew and initially I could not build the project from git:

* 3fe5f6c - (4 weeks ago) Add macOS support — Vertexwahn (HEAD -> add-macos-support, origin/add-macos-support)

This is the result that I get when building:

1brew install qt@5
2brew link qt@5
3bazel run --cxxopt=-std=c++17 //tests/qt_resource:main
4dyld: Symbol not found: __ZN10QByteArray6_emptyE
5# brew install bazel # Install Bazel
6# brew install qt@5  # Install Qt5
7git clone https://github.com/Vertexwahn/bazel_rules_qt.git
8cd bazel_rules_qt
9git checkout add-macos-support
10bazel build --cxxopt=-std=c++17 //... # should work
11bazel run --cxxopt=-std=c++17 //tests/qt_resource:main # should give you the error message
12ERROR: Could not find bundle binary for &quot;main&quot;
13ERROR: &quot;error: /Library/Developer/CommandLineTools/usr/bin/otool-classic: can't open file:  (No such file or directory)\n&quot;
14ERROR: &quot;error: /Library/Developer/CommandLineTools/usr/bin/otool-classic: can't open file:  (No such file or directory)\n&quot;
15ERROR: &quot;error: /Library/Developer/CommandLineTools/usr/bin/otool-classic: can't open file:  (No such file or directory)\n&quot;
16WARNING:
17WARNING: Could not find any external Qt frameworks to deploy in &quot;main&quot;
18WARNING: Perhaps macdeployqt was already used on &quot;main&quot; ?
19WARNING: If so, you will need to rebuild &quot;main&quot; before trying again.
20ERROR: Could not find bundle binary for &quot;main&quot;
21ERROR: &quot;error: /Library/Developer/CommandLineTools/usr/bin/strip: can't open file:  (No such file or directory)\n&quot;
22ERROR: &quot;&quot;
23git clone https://github.com/euler0/mini-cmake-qt.git
24cmake -DCMAKE_PREFIX_PATH=/usr/local/opt/qt5 .
25make -j
26 % bazel build --cxxopt=-std=c++17  //...
27 DEBUG: /private/var/tmp/_bazel_home/761aafaa2237a9607dd915f1f52bca3e/external/com_justbuchanan_rules_qt/qt_configure.bzl:43:14: Installation available on the default path:  /usr/local/opt/qt5
28 INFO: Analyzed 14 targets (0 packages loaded, 0 targets configured).
29 INFO: Found 14 targets...
30 ERROR: /Users/home/Git/my_repo/bazel_rules_qt/tests/qt_qml/BUILD:4:10: Compiling tests/qt_qml/main.cc failed: (Aborted): wrapped_clang failed: error executing command external/local_config_cc/wrapped_clang '-D_FORTIFY_SOURCE=1' -fstack-protector -fcolor-diagnostics -Wall -Wthread-safety -Wself-assign -fno-omit-frame-pointer -O0 -DDEBUG '-std=c++11' ... (remaining 38 argument(s) skipped)
31
32 Use --sandbox_debug to see verbose messages from the sandbox
33 tests/qt_qml/main.cc:1:10: fatal error: 'QtQml/QQmlApplicationEngine' file not found
34 #include &lt;QtQml/QQmlApplicationEngine&gt;
35     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
36 1 error generated.
37 Error in child process '/usr/bin/xcrun'. 1
38 INFO: Elapsed time: 0,594s, Critical Path: 0,32s
39 INFO: 3 processes: 3 internal.
40 FAILED: Build did NOT complete successfully
41

After playing around with headers and include paths in qt.BUILD:

1brew install qt@5
2brew link qt@5
3bazel run --cxxopt=-std=c++17 //tests/qt_resource:main
4dyld: Symbol not found: __ZN10QByteArray6_emptyE
5# brew install bazel # Install Bazel
6# brew install qt@5  # Install Qt5
7git clone https://github.com/Vertexwahn/bazel_rules_qt.git
8cd bazel_rules_qt
9git checkout add-macos-support
10bazel build --cxxopt=-std=c++17 //... # should work
11bazel run --cxxopt=-std=c++17 //tests/qt_resource:main # should give you the error message
12ERROR: Could not find bundle binary for &quot;main&quot;
13ERROR: &quot;error: /Library/Developer/CommandLineTools/usr/bin/otool-classic: can't open file:  (No such file or directory)\n&quot;
14ERROR: &quot;error: /Library/Developer/CommandLineTools/usr/bin/otool-classic: can't open file:  (No such file or directory)\n&quot;
15ERROR: &quot;error: /Library/Developer/CommandLineTools/usr/bin/otool-classic: can't open file:  (No such file or directory)\n&quot;
16WARNING:
17WARNING: Could not find any external Qt frameworks to deploy in &quot;main&quot;
18WARNING: Perhaps macdeployqt was already used on &quot;main&quot; ?
19WARNING: If so, you will need to rebuild &quot;main&quot; before trying again.
20ERROR: Could not find bundle binary for &quot;main&quot;
21ERROR: &quot;error: /Library/Developer/CommandLineTools/usr/bin/strip: can't open file:  (No such file or directory)\n&quot;
22ERROR: &quot;&quot;
23git clone https://github.com/euler0/mini-cmake-qt.git
24cmake -DCMAKE_PREFIX_PATH=/usr/local/opt/qt5 .
25make -j
26 % bazel build --cxxopt=-std=c++17  //...
27 DEBUG: /private/var/tmp/_bazel_home/761aafaa2237a9607dd915f1f52bca3e/external/com_justbuchanan_rules_qt/qt_configure.bzl:43:14: Installation available on the default path:  /usr/local/opt/qt5
28 INFO: Analyzed 14 targets (0 packages loaded, 0 targets configured).
29 INFO: Found 14 targets...
30 ERROR: /Users/home/Git/my_repo/bazel_rules_qt/tests/qt_qml/BUILD:4:10: Compiling tests/qt_qml/main.cc failed: (Aborted): wrapped_clang failed: error executing command external/local_config_cc/wrapped_clang '-D_FORTIFY_SOURCE=1' -fstack-protector -fcolor-diagnostics -Wall -Wthread-safety -Wself-assign -fno-omit-frame-pointer -O0 -DDEBUG '-std=c++11' ... (remaining 38 argument(s) skipped)
31
32 Use --sandbox_debug to see verbose messages from the sandbox
33 tests/qt_qml/main.cc:1:10: fatal error: 'QtQml/QQmlApplicationEngine' file not found
34 #include &lt;QtQml/QQmlApplicationEngine&gt;
35     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
36 1 error generated.
37 Error in child process '/usr/bin/xcrun'. 1
38 INFO: Elapsed time: 0,594s, Critical Path: 0,32s
39 INFO: 3 processes: 3 internal.
40 FAILED: Build did NOT complete successfully
41 diff --git a/qt.BUILD b/qt.BUILD
42 index 517c8db..8f110b5 100644
43 --- a/qt.BUILD
44 +++ b/qt.BUILD
45 @@ -28,11 +28,12 @@ QT_LIBRARIES = [
46      cc_library(
47          name = &quot;qt_%s_osx&quot; % name,
48          # When being on Windows this glob will be empty
49 -        hdrs = glob([&quot;%s/**&quot; % include_folder], allow_empty = True),
50 +        hdrs = glob([&quot;include/%s/**&quot; % include_folder], allow_empty = True),
51          includes = [&quot;.&quot;],
52          linkopts = [&quot;-F/usr/local/opt/qt5/lib&quot;] + [
53              &quot;-framework %s&quot; % library_name.replace(&quot;5&quot;, &quot;&quot;) # macOS qt libs do not contain a 5 - e.g. instead of Qt5Core the lib is called QtCore
54              ],
55 +        strip_include_prefix= &quot;include&quot;
56          # Available from Bazel 4.0.0
57          # target_compatible_with = [&quot;@platforms//os:osx&quot;],
58      )
59

I could build and run the project:

1brew install qt@5
2brew link qt@5
3bazel run --cxxopt=-std=c++17 //tests/qt_resource:main
4dyld: Symbol not found: __ZN10QByteArray6_emptyE
5# brew install bazel # Install Bazel
6# brew install qt@5  # Install Qt5
7git clone https://github.com/Vertexwahn/bazel_rules_qt.git
8cd bazel_rules_qt
9git checkout add-macos-support
10bazel build --cxxopt=-std=c++17 //... # should work
11bazel run --cxxopt=-std=c++17 //tests/qt_resource:main # should give you the error message
12ERROR: Could not find bundle binary for &quot;main&quot;
13ERROR: &quot;error: /Library/Developer/CommandLineTools/usr/bin/otool-classic: can't open file:  (No such file or directory)\n&quot;
14ERROR: &quot;error: /Library/Developer/CommandLineTools/usr/bin/otool-classic: can't open file:  (No such file or directory)\n&quot;
15ERROR: &quot;error: /Library/Developer/CommandLineTools/usr/bin/otool-classic: can't open file:  (No such file or directory)\n&quot;
16WARNING:
17WARNING: Could not find any external Qt frameworks to deploy in &quot;main&quot;
18WARNING: Perhaps macdeployqt was already used on &quot;main&quot; ?
19WARNING: If so, you will need to rebuild &quot;main&quot; before trying again.
20ERROR: Could not find bundle binary for &quot;main&quot;
21ERROR: &quot;error: /Library/Developer/CommandLineTools/usr/bin/strip: can't open file:  (No such file or directory)\n&quot;
22ERROR: &quot;&quot;
23git clone https://github.com/euler0/mini-cmake-qt.git
24cmake -DCMAKE_PREFIX_PATH=/usr/local/opt/qt5 .
25make -j
26 % bazel build --cxxopt=-std=c++17  //...
27 DEBUG: /private/var/tmp/_bazel_home/761aafaa2237a9607dd915f1f52bca3e/external/com_justbuchanan_rules_qt/qt_configure.bzl:43:14: Installation available on the default path:  /usr/local/opt/qt5
28 INFO: Analyzed 14 targets (0 packages loaded, 0 targets configured).
29 INFO: Found 14 targets...
30 ERROR: /Users/home/Git/my_repo/bazel_rules_qt/tests/qt_qml/BUILD:4:10: Compiling tests/qt_qml/main.cc failed: (Aborted): wrapped_clang failed: error executing command external/local_config_cc/wrapped_clang '-D_FORTIFY_SOURCE=1' -fstack-protector -fcolor-diagnostics -Wall -Wthread-safety -Wself-assign -fno-omit-frame-pointer -O0 -DDEBUG '-std=c++11' ... (remaining 38 argument(s) skipped)
31
32 Use --sandbox_debug to see verbose messages from the sandbox
33 tests/qt_qml/main.cc:1:10: fatal error: 'QtQml/QQmlApplicationEngine' file not found
34 #include &lt;QtQml/QQmlApplicationEngine&gt;
35     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
36 1 error generated.
37 Error in child process '/usr/bin/xcrun'. 1
38 INFO: Elapsed time: 0,594s, Critical Path: 0,32s
39 INFO: 3 processes: 3 internal.
40 FAILED: Build did NOT complete successfully
41 diff --git a/qt.BUILD b/qt.BUILD
42 index 517c8db..8f110b5 100644
43 --- a/qt.BUILD
44 +++ b/qt.BUILD
45 @@ -28,11 +28,12 @@ QT_LIBRARIES = [
46      cc_library(
47          name = &quot;qt_%s_osx&quot; % name,
48          # When being on Windows this glob will be empty
49 -        hdrs = glob([&quot;%s/**&quot; % include_folder], allow_empty = True),
50 +        hdrs = glob([&quot;include/%s/**&quot; % include_folder], allow_empty = True),
51          includes = [&quot;.&quot;],
52          linkopts = [&quot;-F/usr/local/opt/qt5/lib&quot;] + [
53              &quot;-framework %s&quot; % library_name.replace(&quot;5&quot;, &quot;&quot;) # macOS qt libs do not contain a 5 - e.g. instead of Qt5Core the lib is called QtCore
54              ],
55 +        strip_include_prefix= &quot;include&quot;
56          # Available from Bazel 4.0.0
57          # target_compatible_with = [&quot;@platforms//os:osx&quot;],
58      )
59 % bazel build --cxxopt=-std=c++17  //...
60 DEBUG: /private/var/tmp/_bazel_home/761aafaa2237a9607dd915f1f52bca3e/external/com_justbuchanan_rules_qt/qt_configure.bzl:43:14: Installation available on the default path:  /usr/local/opt/qt5
61 INFO: Analyzed 14 targets (1 packages loaded, 7422 targets configured).
62 INFO: Found 14 targets...
63 INFO: Elapsed time: 11,761s, Critical Path: 7,23s
64 INFO: 3 processes: 1 internal, 2 darwin-sandbox.
65 INFO: Build completed successfully, 3 total actions
66 % bazel run --cxxopt=-std=c++17 //tests/qt_resource:main
67 DEBUG: /private/var/tmp/_bazel_home/761aafaa2237a9607dd915f1f52bca3e/external/com_justbuchanan_rules_qt/qt_configure.bzl:43:14: Installation available on the default path:  /usr/local/opt/qt5
68 INFO: Analyzed target //tests/qt_resource:main (0 packages loaded, 0 targets configured).
69 INFO: Found 1 target...
70 Target //tests/qt_resource:main up-to-date:
71 bazel-bin/tests/qt_resource/main
72 INFO: Elapsed time: 3,657s, Critical Path: 0,00s
73 INFO: 1 process: 1 internal.
74 INFO: Build completed successfully, 1 total action
75 INFO: Build completed successfully, 1 total action
76 opened resource file
77 file1
78

Related to your question whether the linker options are correct -F/usr/local/opt/qt5/Frameworks -framework QtCore

Yes they are correct, you could alternatively use -F/usr/local/opt/qt5/lib (as you are already using in qt.BUILD) as all the files under the Frameworks folder are links to the lib folder.

With macdeployqt and lipo I get the same results as in the OP even after the test is running successfully.

Source https://stackoverflow.com/questions/71040975

QUESTION

CMake: How to compile with different library versions of Qt?

Asked 2022-Feb-15 at 20:06

How do you get CMake to compile conditionally with Qt4.8 or Qt5? In other words, if Qt5 is available then compile with Qt5. Otherwise if Qt4.8 is available use that.

In my CMake, I have:

1find_package(Qt5 COMPONENTS Core Gui Widgets...)
2

This works fine with my Qt5 builds, but how do I get the same software to build with Qt4.8?

I need something that contains the major version number, eg.:

1find_package(Qt5 COMPONENTS Core Gui Widgets...)
2find_package(Qt $QT_VERSION_MAJOR...)
3

or to use a condition, such as:

1find_package(Qt5 COMPONENTS Core Gui Widgets...)
2find_package(Qt $QT_VERSION_MAJOR...)
3result = find_package(Qt 5...)
4if (!result) then find_package(Qt4 ...)
5

or somehow detect the currently install Qt version.

The error I get for the machine with Qt4.8 installed is (unsurprisingly):

1find_package(Qt5 COMPONENTS Core Gui Widgets...)
2find_package(Qt $QT_VERSION_MAJOR...)
3result = find_package(Qt 5...)
4if (!result) then find_package(Qt4 ...)
5CMake Error at CMakeLists.txt:54 (find_package):
6  By not providing &quot;FindQt5.cmake&quot; in CMAKE_MODULE_PATH this project has
7  asked CMake to find a package configuration file provided by &quot;Qt5&quot;, but
8  CMake did not find one.
9
10  Could not find a package configuration file provided by &quot;Qt5&quot; with any of
11  the following names:
12
13    Qt5Config.cmake
14

What is the best approach here?

ANSWER

Answered 2022-Feb-15 at 20:06

Automatically selecting an available version of Qt is fairly easy with the NAME option of the find_package command. The problem is that Qt4 and Qt5 have different names for the same modules.

1find_package(Qt5 COMPONENTS Core Gui Widgets...)
2find_package(Qt $QT_VERSION_MAJOR...)
3result = find_package(Qt 5...)
4if (!result) then find_package(Qt4 ...)
5CMake Error at CMakeLists.txt:54 (find_package):
6  By not providing &quot;FindQt5.cmake&quot; in CMAKE_MODULE_PATH this project has
7  asked CMake to find a package configuration file provided by &quot;Qt5&quot;, but
8  CMake did not find one.
9
10  Could not find a package configuration file provided by &quot;Qt5&quot; with any of
11  the following names:
12
13    Qt5Config.cmake
14# We first try to find the main module of Qt4, Qt5 or Qt6
15find_package(QT NAMES Qt4 Qt5 Qt6 REQUIRED)
16set(QT Qt${QT_VERSION_MAJOR})
17
18# We prepare lists of modules and libraries for different
19# versions of Qt
20if (QT_VERSION_MAJOR EQUAL 4)
21    set(APP_QT_MODULES QtCore QtNetwork QtGui QtXml)
22    set(APP_QT_TARGETS Qt4::QtCore Qt4::QtNetwork Qt4::QtGui Qt4::QtXml)
23else ()
24    set(APP_QT_MODULES Core Network PrintSupport Widgets Xml)
25    set(APP_QT_TARGETS ${QT}::Core ${QT}::Network ${QT}::PrintSupport ${QT}::Widgets ${QT}::Xml)
26endif ()
27
28# Here everything is simple - find the modules we need.
29find_package(${QT} REQUIRED ${APP_QT_MODULES})
30
31. . .
32. . .
33
34# And at last don't forget to add libraries.
35add_executable(my_app app.cpp main.cpp window.cpp)
36target_link_libraries(my_app ${APP_QT_TARGETS})
37

Another problem is that Qt functions have different names too, for example qt4_add_resources and qt5_add_resources. And this is a good reason to wonder whether or not you really need Qt4 support in your project.

Update

We can make Qt function aliases (as is done in Qt since version 5.15).

1find_package(Qt5 COMPONENTS Core Gui Widgets...)
2find_package(Qt $QT_VERSION_MAJOR...)
3result = find_package(Qt 5...)
4if (!result) then find_package(Qt4 ...)
5CMake Error at CMakeLists.txt:54 (find_package):
6  By not providing &quot;FindQt5.cmake&quot; in CMAKE_MODULE_PATH this project has
7  asked CMake to find a package configuration file provided by &quot;Qt5&quot;, but
8  CMake did not find one.
9
10  Could not find a package configuration file provided by &quot;Qt5&quot; with any of
11  the following names:
12
13    Qt5Config.cmake
14# We first try to find the main module of Qt4, Qt5 or Qt6
15find_package(QT NAMES Qt4 Qt5 Qt6 REQUIRED)
16set(QT Qt${QT_VERSION_MAJOR})
17
18# We prepare lists of modules and libraries for different
19# versions of Qt
20if (QT_VERSION_MAJOR EQUAL 4)
21    set(APP_QT_MODULES QtCore QtNetwork QtGui QtXml)
22    set(APP_QT_TARGETS Qt4::QtCore Qt4::QtNetwork Qt4::QtGui Qt4::QtXml)
23else ()
24    set(APP_QT_MODULES Core Network PrintSupport Widgets Xml)
25    set(APP_QT_TARGETS ${QT}::Core ${QT}::Network ${QT}::PrintSupport ${QT}::Widgets ${QT}::Xml)
26endif ()
27
28# Here everything is simple - find the modules we need.
29find_package(${QT} REQUIRED ${APP_QT_MODULES})
30
31. . .
32. . .
33
34# And at last don't forget to add libraries.
35add_executable(my_app app.cpp main.cpp window.cpp)
36target_link_libraries(my_app ${APP_QT_TARGETS})
37if (QT_VERSION VERSION_LESS 5.15)
38    macro(qt_wrap_cpp)
39        ${QT}_wrap_cpp(${ARGV})
40    endmacro()
41
42    macro(qt_add_resources)
43        ${QT}_add_resources(${ARGV})
44    endmacro()
45
46    macro(qt_generate_moc)
47        ${QT}_generate_moc(${ARGV})
48    endmacro()
49endif ()
50

Source https://stackoverflow.com/questions/71130219

QUESTION

How to install websockets for Qt 6?

Asked 2022-Feb-10 at 18:45

Already referred below old posts, but its solution of installing websockets didn't work in my Ubuntu 21.10.

This could be probably due to my Qt is 6.2, while the available library is from Qt5, viz. libqt5websockets5-dev.

How to install websocket module properly for the Qt6, to fix below error?

Project ERROR: Unknown module(s) in QT: websockets

ANSWER

Answered 2022-Feb-10 at 18:45

When installing Qt via Qt Maintenance Tool, just go to Additional Libraries and check QtWebSockets. It is available in Qt 6.2.x versions.

enter image description here

Source https://stackoverflow.com/questions/71064756

QUESTION

How to make unique_ptr work with Qt's QHash and QString?

Asked 2022-Jan-29 at 20:52

I am learning the intrincacies of unique_ptr.

I have a working example of a std::unordered_map that holds std:string and std::unique_ptr<std::string>.

But I can't make unique_ptr examples with Qt's QString and QHash work. They won't compile mentioning errors like use of deleted function.

How can I make the two last examples work?

Edit 1

In case this info is relevant, I am using gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0.

Example 1 (working): unordered_map and string unordered_map_string.h
1#ifndef UNORDERED_MAP_STRING_H
2#define UNORDERED_MAP_STRING_H
3
4#include &lt;memory&gt;
5#include &lt;string&gt;
6#include &lt;unordered_map&gt;
7
8class UnorderedMapString
9{
10public:
11    UnorderedMapString() {};
12
13    std::unordered_map&lt;std::string, std::unique_ptr&lt;std::string&gt;&gt; container;
14
15    void addItem(std::string aKey, std::unique_ptr&lt;std::string&gt; aValue);
16
17    void showItem(std::string aKey);
18};
19
20#endif // UNORDERED_MAP_STRING_H
21
unordered_map_string.cpp
1#ifndef UNORDERED_MAP_STRING_H
2#define UNORDERED_MAP_STRING_H
3
4#include &lt;memory&gt;
5#include &lt;string&gt;
6#include &lt;unordered_map&gt;
7
8class UnorderedMapString
9{
10public:
11    UnorderedMapString() {};
12
13    std::unordered_map&lt;std::string, std::unique_ptr&lt;std::string&gt;&gt; container;
14
15    void addItem(std::string aKey, std::unique_ptr&lt;std::string&gt; aValue);
16
17    void showItem(std::string aKey);
18};
19
20#endif // UNORDERED_MAP_STRING_H
21#include &quot;unordered_map_string.h&quot;
22
23#include &lt;iostream&gt;
24
25void UnorderedMapString::addItem(std::string aKey, std::unique_ptr&lt;std::string&gt; aValue)
26{
27    container[aKey] = std::move(aValue);
28}
29
30void UnorderedMapString::showItem(std::string aKey)
31{
32    std::string *aValue = container[aKey].get();
33    std::cout &lt;&lt; &quot;Item '&quot; &lt;&lt; aKey &lt;&lt; &quot;': '&quot; &lt;&lt; *aValue &lt;&lt; &quot;'\n&quot;;
34}
35
main.cpp
1#ifndef UNORDERED_MAP_STRING_H
2#define UNORDERED_MAP_STRING_H
3
4#include &lt;memory&gt;
5#include &lt;string&gt;
6#include &lt;unordered_map&gt;
7
8class UnorderedMapString
9{
10public:
11    UnorderedMapString() {};
12
13    std::unordered_map&lt;std::string, std::unique_ptr&lt;std::string&gt;&gt; container;
14
15    void addItem(std::string aKey, std::unique_ptr&lt;std::string&gt; aValue);
16
17    void showItem(std::string aKey);
18};
19
20#endif // UNORDERED_MAP_STRING_H
21#include &quot;unordered_map_string.h&quot;
22
23#include &lt;iostream&gt;
24
25void UnorderedMapString::addItem(std::string aKey, std::unique_ptr&lt;std::string&gt; aValue)
26{
27    container[aKey] = std::move(aValue);
28}
29
30void UnorderedMapString::showItem(std::string aKey)
31{
32    std::string *aValue = container[aKey].get();
33    std::cout &lt;&lt; &quot;Item '&quot; &lt;&lt; aKey &lt;&lt; &quot;': '&quot; &lt;&lt; *aValue &lt;&lt; &quot;'\n&quot;;
34}
35#include &quot;unordered_map_string.h&quot;
36
37#include &lt;memory&gt;
38
39int main(int argc, char *argv[])
40{
41    UnorderedMapString testContainer;
42
43    testContainer.addItem(&quot;key 1&quot;, std::make_unique&lt;std::string&gt;(&quot;one value&quot;));
44    testContainer.addItem(&quot;key 2&quot;, std::make_unique&lt;std::string&gt;(&quot;two value&quot;));
45    testContainer.addItem(&quot;key 3&quot;, std::make_unique&lt;std::string&gt;(&quot;three value&quot;));
46
47    testContainer.showItem(&quot;key 2&quot;);
48    testContainer.showItem(&quot;key 3&quot;);
49    testContainer.showItem(&quot;key 2&quot;);
50
51    return 0;
52}
53
CMakeLists.txt
1#ifndef UNORDERED_MAP_STRING_H
2#define UNORDERED_MAP_STRING_H
3
4#include &lt;memory&gt;
5#include &lt;string&gt;
6#include &lt;unordered_map&gt;
7
8class UnorderedMapString
9{
10public:
11    UnorderedMapString() {};
12
13    std::unordered_map&lt;std::string, std::unique_ptr&lt;std::string&gt;&gt; container;
14
15    void addItem(std::string aKey, std::unique_ptr&lt;std::string&gt; aValue);
16
17    void showItem(std::string aKey);
18};
19
20#endif // UNORDERED_MAP_STRING_H
21#include &quot;unordered_map_string.h&quot;
22
23#include &lt;iostream&gt;
24
25void UnorderedMapString::addItem(std::string aKey, std::unique_ptr&lt;std::string&gt; aValue)
26{
27    container[aKey] = std::move(aValue);
28}
29
30void UnorderedMapString::showItem(std::string aKey)
31{
32    std::string *aValue = container[aKey].get();
33    std::cout &lt;&lt; &quot;Item '&quot; &lt;&lt; aKey &lt;&lt; &quot;': '&quot; &lt;&lt; *aValue &lt;&lt; &quot;'\n&quot;;
34}
35#include &quot;unordered_map_string.h&quot;
36
37#include &lt;memory&gt;
38
39int main(int argc, char *argv[])
40{
41    UnorderedMapString testContainer;
42
43    testContainer.addItem(&quot;key 1&quot;, std::make_unique&lt;std::string&gt;(&quot;one value&quot;));
44    testContainer.addItem(&quot;key 2&quot;, std::make_unique&lt;std::string&gt;(&quot;two value&quot;));
45    testContainer.addItem(&quot;key 3&quot;, std::make_unique&lt;std::string&gt;(&quot;three value&quot;));
46
47    testContainer.showItem(&quot;key 2&quot;);
48    testContainer.showItem(&quot;key 3&quot;);
49    testContainer.showItem(&quot;key 2&quot;);
50
51    return 0;
52}
53cmake_minimum_required(VERSION 3.14)
54
55project(unique_ptr_string LANGUAGES CXX)
56
57set(CMAKE_INCLUDE_CURRENT_DIR ON)
58
59set(CMAKE_CXX_STANDARD 17)
60set(CMAKE_CXX_STANDARD_REQUIRED ON)
61
62add_executable(unique_ptr_string
63  main.cpp
64  unordered_map_string.h unordered_map_string.cpp
65)
66
Example 2 (not working): unordered_map and QString unordered_map_qstring.h
1#ifndef UNORDERED_MAP_STRING_H
2#define UNORDERED_MAP_STRING_H
3
4#include &lt;memory&gt;
5#include &lt;string&gt;
6#include &lt;unordered_map&gt;
7
8class UnorderedMapString
9{
10public:
11    UnorderedMapString() {};
12
13    std::unordered_map&lt;std::string, std::unique_ptr&lt;std::string&gt;&gt; container;
14
15    void addItem(std::string aKey, std::unique_ptr&lt;std::string&gt; aValue);
16
17    void showItem(std::string aKey);
18};
19
20#endif // UNORDERED_MAP_STRING_H
21#include &quot;unordered_map_string.h&quot;
22
23#include &lt;iostream&gt;
24
25void UnorderedMapString::addItem(std::string aKey, std::unique_ptr&lt;std::string&gt; aValue)
26{
27    container[aKey] = std::move(aValue);
28}
29
30void UnorderedMapString::showItem(std::string aKey)
31{
32    std::string *aValue = container[aKey].get();
33    std::cout &lt;&lt; &quot;Item '&quot; &lt;&lt; aKey &lt;&lt; &quot;': '&quot; &lt;&lt; *aValue &lt;&lt; &quot;'\n&quot;;
34}
35#include &quot;unordered_map_string.h&quot;
36
37#include &lt;memory&gt;
38
39int main(int argc, char *argv[])
40{
41    UnorderedMapString testContainer;
42
43    testContainer.addItem(&quot;key 1&quot;, std::make_unique&lt;std::string&gt;(&quot;one value&quot;));
44    testContainer.addItem(&quot;key 2&quot;, std::make_unique&lt;std::string&gt;(&quot;two value&quot;));
45    testContainer.addItem(&quot;key 3&quot;, std::make_unique&lt;std::string&gt;(&quot;three value&quot;));
46
47    testContainer.showItem(&quot;key 2&quot;);
48    testContainer.showItem(&quot;key 3&quot;);
49    testContainer.showItem(&quot;key 2&quot;);
50
51    return 0;
52}
53cmake_minimum_required(VERSION 3.14)
54
55project(unique_ptr_string LANGUAGES CXX)
56
57set(CMAKE_INCLUDE_CURRENT_DIR ON)
58
59set(CMAKE_CXX_STANDARD 17)
60set(CMAKE_CXX_STANDARD_REQUIRED ON)
61
62add_executable(unique_ptr_string
63  main.cpp
64  unordered_map_string.h unordered_map_string.cpp
65)
66#ifndef UNORDERED_MAP_QSTRING_H
67#define UNORDERED_MAP_QSTRING_H
68
69#include &lt;QString&gt;
70
71#include &lt;memory&gt;
72#include &lt;unordered_map&gt;
73
74class UnorderedMapQString
75{
76public:
77    UnorderedMapQString() {};
78
79    std::unordered_map&lt;QString, std::unique_ptr&lt;QString&gt;&gt; container;
80
81    void addItem(QString aKey, std::unique_ptr&lt;QString&gt; aValue);
82
83    void showItem(QString aKey);
84};
85
86#endif // UNORDERED_MAP_QSTRING_H
87
unordered_map_qstring.cpp
1#ifndef UNORDERED_MAP_STRING_H
2#define UNORDERED_MAP_STRING_H
3
4#include &lt;memory&gt;
5#include &lt;string&gt;
6#include &lt;unordered_map&gt;
7
8class UnorderedMapString
9{
10public:
11    UnorderedMapString() {};
12
13    std::unordered_map&lt;std::string, std::unique_ptr&lt;std::string&gt;&gt; container;
14
15    void addItem(std::string aKey, std::unique_ptr&lt;std::string&gt; aValue);
16
17    void showItem(std::string aKey);
18};
19
20#endif // UNORDERED_MAP_STRING_H
21#include &quot;unordered_map_string.h&quot;
22
23#include &lt;iostream&gt;
24
25void UnorderedMapString::addItem(std::string aKey, std::unique_ptr&lt;std::string&gt; aValue)
26{
27    container[aKey] = std::move(aValue);
28}
29
30void UnorderedMapString::showItem(std::string aKey)
31{
32    std::string *aValue = container[aKey].get();
33    std::cout &lt;&lt; &quot;Item '&quot; &lt;&lt; aKey &lt;&lt; &quot;': '&quot; &lt;&lt; *aValue &lt;&lt; &quot;'\n&quot;;
34}
35#include &quot;unordered_map_string.h&quot;
36
37#include &lt;memory&gt;
38
39int main(int argc, char *argv[])
40{
41    UnorderedMapString testContainer;
42
43    testContainer.addItem(&quot;key 1&quot;, std::make_unique&lt;std::string&gt;(&quot;one value&quot;));
44    testContainer.addItem(&quot;key 2&quot;, std::make_unique&lt;std::string&gt;(&quot;two value&quot;));
45    testContainer.addItem(&quot;key 3&quot;, std::make_unique&lt;std::string&gt;(&quot;three value&quot;));
46
47    testContainer.showItem(&quot;key 2&quot;);
48    testContainer.showItem(&quot;key 3&quot;);
49    testContainer.showItem(&quot;key 2&quot;);
50
51    return 0;
52}
53cmake_minimum_required(VERSION 3.14)
54
55project(unique_ptr_string LANGUAGES CXX)
56
57set(CMAKE_INCLUDE_CURRENT_DIR ON)
58
59set(CMAKE_CXX_STANDARD 17)
60set(CMAKE_CXX_STANDARD_REQUIRED ON)
61
62add_executable(unique_ptr_string
63  main.cpp
64  unordered_map_string.h unordered_map_string.cpp
65)
66#ifndef UNORDERED_MAP_QSTRING_H
67#define UNORDERED_MAP_QSTRING_H
68
69#include &lt;QString&gt;
70
71#include &lt;memory&gt;
72#include &lt;unordered_map&gt;
73
74class UnorderedMapQString
75{
76public:
77    UnorderedMapQString() {};
78
79    std::unordered_map&lt;QString, std::unique_ptr&lt;QString&gt;&gt; container;
80
81    void addItem(QString aKey, std::unique_ptr&lt;QString&gt; aValue);
82
83    void showItem(QString aKey);
84};
85
86#endif // UNORDERED_MAP_QSTRING_H
87#include &quot;unordered_map_qstring.h&quot;
88
89#include &lt;iostream&gt;
90
91void UnorderedMapQString::addItem(QString aKey, std::unique_ptr&lt;QString&gt; aValue)
92{
93    container[aKey] = std::move(aValue);
94}
95
96void UnorderedMapQString::showItem(QString aKey)
97{
98    QString *aValue = container[aKey].get();
99    std::cout &lt;&lt; &quot;Item '&quot; &lt;&lt; aKey.toStdString() &lt;&lt; &quot;': '&quot; &lt;&lt; (*aValue).toStdString() &lt;&lt; &quot;'\n&quot;;
100}
101
main.cpp
1#ifndef UNORDERED_MAP_STRING_H
2#define UNORDERED_MAP_STRING_H
3
4#include &lt;memory&gt;
5#include &lt;string&gt;
6#include &lt;unordered_map&gt;
7
8class UnorderedMapString
9{
10public:
11    UnorderedMapString() {};
12
13    std::unordered_map&lt;std::string, std::unique_ptr&lt;std::string&gt;&gt; container;
14
15    void addItem(std::string aKey, std::unique_ptr&lt;std::string&gt; aValue);
16
17    void showItem(std::string aKey);
18};
19
20#endif // UNORDERED_MAP_STRING_H
21#include &quot;unordered_map_string.h&quot;
22
23#include &lt;iostream&gt;
24
25void UnorderedMapString::addItem(std::string aKey, std::unique_ptr&lt;std::string&gt; aValue)
26{
27    container[aKey] = std::move(aValue);
28}
29
30void UnorderedMapString::showItem(std::string aKey)
31{
32    std::string *aValue = container[aKey].get();
33    std::cout &lt;&lt; &quot;Item '&quot; &lt;&lt; aKey &lt;&lt; &quot;': '&quot; &lt;&lt; *aValue &lt;&lt; &quot;'\n&quot;;
34}
35#include &quot;unordered_map_string.h&quot;
36
37#include &lt;memory&gt;
38
39int main(int argc, char *argv[])
40{
41    UnorderedMapString testContainer;
42
43    testContainer.addItem(&quot;key 1&quot;, std::make_unique&lt;std::string&gt;(&quot;one value&quot;));
44    testContainer.addItem(&quot;key 2&quot;, std::make_unique&lt;std::string&gt;(&quot;two value&quot;));
45    testContainer.addItem(&quot;key 3&quot;, std::make_unique&lt;std::string&gt;(&quot;three value&quot;));
46
47    testContainer.showItem(&quot;key 2&quot;);
48    testContainer.showItem(&quot;key 3&quot;);
49    testContainer.showItem(&quot;key 2&quot;);
50
51    return 0;
52}
53cmake_minimum_required(VERSION 3.14)
54
55project(unique_ptr_string LANGUAGES CXX)
56
57set(CMAKE_INCLUDE_CURRENT_DIR ON)
58
59set(CMAKE_CXX_STANDARD 17)
60set(CMAKE_CXX_STANDARD_REQUIRED ON)
61
62add_executable(unique_ptr_string
63  main.cpp
64  unordered_map_string.h unordered_map_string.cpp
65)
66#ifndef UNORDERED_MAP_QSTRING_H
67#define UNORDERED_MAP_QSTRING_H
68
69#include &lt;QString&gt;
70
71#include &lt;memory&gt;
72#include &lt;unordered_map&gt;
73
74class UnorderedMapQString
75{
76public:
77    UnorderedMapQString() {};
78
79    std::unordered_map&lt;QString, std::unique_ptr&lt;QString&gt;&gt; container;
80
81    void addItem(QString aKey, std::unique_ptr&lt;QString&gt; aValue);
82
83    void showItem(QString aKey);
84};
85
86#endif // UNORDERED_MAP_QSTRING_H
87#include &quot;unordered_map_qstring.h&quot;
88
89#include &lt;iostream&gt;
90
91void UnorderedMapQString::addItem(QString aKey, std::unique_ptr&lt;QString&gt; aValue)
92{
93    container[aKey] = std::move(aValue);
94}
95
96void UnorderedMapQString::showItem(QString aKey)
97{
98    QString *aValue = container[aKey].get();
99    std::cout &lt;&lt; &quot;Item '&quot; &lt;&lt; aKey.toStdString() &lt;&lt; &quot;': '&quot; &lt;&lt; (*aValue).toStdString() &lt;&lt; &quot;'\n&quot;;
100}
101#include &quot;unordered_map_qstring.h&quot;
102
103#include &lt;QString&gt;
104
105#include &lt;memory&gt;
106
107int main(int argc, char *argv[])
108{
109    UnorderedMapQString testContainer;
110
111    testContainer.addItem(&quot;key 1&quot;, std::make_unique&lt;QString&gt;(&quot;one value&quot;));
112    testContainer.addItem(&quot;key 2&quot;, std::make_unique&lt;QString&gt;(&quot;two value&quot;));
113    testContainer.addItem(&quot;key 3&quot;, std::make_unique&lt;QString&gt;(&quot;three value&quot;));
114
115    testContainer.showItem(&quot;key 2&quot;);
116    testContainer.showItem(&quot;key 3&quot;);
117    testContainer.showItem(&quot;key 2&quot;);
118
119    return 0;
120}
121
CMakeLists.txt
1#ifndef UNORDERED_MAP_STRING_H
2#define UNORDERED_MAP_STRING_H
3
4#include &lt;memory&gt;
5#include &lt;string&gt;
6#include &lt;unordered_map&gt;
7
8class UnorderedMapString
9{
10public:
11    UnorderedMapString() {};
12
13    std::unordered_map&lt;std::string, std::unique_ptr&lt;std::string&gt;&gt; container;
14
15    void addItem(std::string aKey, std::unique_ptr&lt;std::string&gt; aValue);
16
17    void showItem(std::string aKey);
18};
19
20#endif // UNORDERED_MAP_STRING_H
21#include &quot;unordered_map_string.h&quot;
22
23#include &lt;iostream&gt;
24
25void UnorderedMapString::addItem(std::string aKey, std::unique_ptr&lt;std::string&gt; aValue)
26{
27    container[aKey] = std::move(aValue);
28}
29
30void UnorderedMapString::showItem(std::string aKey)
31{
32    std::string *aValue = container[aKey].get();
33    std::cout &lt;&lt; &quot;Item '&quot; &lt;&lt; aKey &lt;&lt; &quot;': '&quot; &lt;&lt; *aValue &lt;&lt; &quot;'\n&quot;;
34}
35#include &quot;unordered_map_string.h&quot;
36
37#include &lt;memory&gt;
38
39int main(int argc, char *argv[])
40{
41    UnorderedMapString testContainer;
42
43    testContainer.addItem(&quot;key 1&quot;, std::make_unique&lt;std::string&gt;(&quot;one value&quot;));
44    testContainer.addItem(&quot;key 2&quot;, std::make_unique&lt;std::string&gt;(&quot;two value&quot;));
45    testContainer.addItem(&quot;key 3&quot;, std::make_unique&lt;std::string&gt;(&quot;three value&quot;));
46
47    testContainer.showItem(&quot;key 2&quot;);
48    testContainer.showItem(&quot;key 3&quot;);
49    testContainer.showItem(&quot;key 2&quot;);
50
51    return 0;
52}
53cmake_minimum_required(VERSION 3.14)
54
55project(unique_ptr_string LANGUAGES CXX)
56
57set(CMAKE_INCLUDE_CURRENT_DIR ON)
58
59set(CMAKE_CXX_STANDARD 17)
60set(CMAKE_CXX_STANDARD_REQUIRED ON)
61
62add_executable(unique_ptr_string
63  main.cpp
64  unordered_map_string.h unordered_map_string.cpp
65)
66#ifndef UNORDERED_MAP_QSTRING_H
67#define UNORDERED_MAP_QSTRING_H
68
69#include &lt;QString&gt;
70
71#include &lt;memory&gt;
72#include &lt;unordered_map&gt;
73
74class UnorderedMapQString
75{
76public:
77    UnorderedMapQString() {};
78
79    std::unordered_map&lt;QString, std::unique_ptr&lt;QString&gt;&gt; container;
80
81    void addItem(QString aKey, std::unique_ptr&lt;QString&gt; aValue);
82
83    void showItem(QString aKey);
84};
85
86#endif // UNORDERED_MAP_QSTRING_H
87#include &quot;unordered_map_qstring.h&quot;
88
89#include &lt;iostream&gt;
90
91void UnorderedMapQString::addItem(QString aKey, std::unique_ptr&lt;QString&gt; aValue)
92{
93    container[aKey] = std::move(aValue);
94}
95
96void UnorderedMapQString::showItem(QString aKey)
97{
98    QString *aValue = container[aKey].get();
99    std::cout &lt;&lt; &quot;Item '&quot; &lt;&lt; aKey.toStdString() &lt;&lt; &quot;': '&quot; &lt;&lt; (*aValue).toStdString() &lt;&lt; &quot;'\n&quot;;
100}
101#include &quot;unordered_map_qstring.h&quot;
102
103#include &lt;QString&gt;
104
105#include &lt;memory&gt;
106
107int main(int argc, char *argv[])
108{
109    UnorderedMapQString testContainer;
110
111    testContainer.addItem(&quot;key 1&quot;, std::make_unique&lt;QString&gt;(&quot;one value&quot;));
112    testContainer.addItem(&quot;key 2&quot;, std::make_unique&lt;QString&gt;(&quot;two value&quot;));
113    testContainer.addItem(&quot;key 3&quot;, std::make_unique&lt;QString&gt;(&quot;three value&quot;));
114
115    testContainer.showItem(&quot;key 2&quot;);
116    testContainer.showItem(&quot;key 3&quot;);
117    testContainer.showItem(&quot;key 2&quot;);
118
119    return 0;
120}
121cmake_minimum_required(VERSION 3.14)
122
123project(unique_ptr_qstring LANGUAGES CXX)
124
125set(CMAKE_INCLUDE_CURRENT_DIR ON)
126
127set(CMAKE_CXX_STANDARD 17)
128set(CMAKE_CXX_STANDARD_REQUIRED ON)
129
130find_package(QT NAMES Qt6 Qt5 COMPONENTS Core REQUIRED)
131find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core REQUIRED)
132
133add_executable(unique_ptr_qstring
134  main.cpp
135  unordered_map_qstring.h unordered_map_qstring.cpp
136)
137target_link_libraries(unique_ptr_qstring Qt${QT_VERSION_MAJOR}::Core)
138
EDIT 2: compile errors for example 2
1#ifndef UNORDERED_MAP_STRING_H
2#define UNORDERED_MAP_STRING_H
3
4#include &lt;memory&gt;
5#include &lt;string&gt;
6#include &lt;unordered_map&gt;
7
8class UnorderedMapString
9{
10public:
11    UnorderedMapString() {};
12
13    std::unordered_map&lt;std::string, std::unique_ptr&lt;std::string&gt;&gt; container;
14
15    void addItem(std::string aKey, std::unique_ptr&lt;std::string&gt; aValue);
16
17    void showItem(std::string aKey);
18};
19
20#endif // UNORDERED_MAP_STRING_H
21#include &quot;unordered_map_string.h&quot;
22
23#include &lt;iostream&gt;
24
25void UnorderedMapString::addItem(std::string aKey, std::unique_ptr&lt;std::string&gt; aValue)
26{
27    container[aKey] = std::move(aValue);
28}
29
30void UnorderedMapString::showItem(std::string aKey)
31{
32    std::string *aValue = container[aKey].get();
33    std::cout &lt;&lt; &quot;Item '&quot; &lt;&lt; aKey &lt;&lt; &quot;': '&quot; &lt;&lt; *aValue &lt;&lt; &quot;'\n&quot;;
34}
35#include &quot;unordered_map_string.h&quot;
36
37#include &lt;memory&gt;
38
39int main(int argc, char *argv[])
40{
41    UnorderedMapString testContainer;
42
43    testContainer.addItem(&quot;key 1&quot;, std::make_unique&lt;std::string&gt;(&quot;one value&quot;));
44    testContainer.addItem(&quot;key 2&quot;, std::make_unique&lt;std::string&gt;(&quot;two value&quot;));
45    testContainer.addItem(&quot;key 3&quot;, std::make_unique&lt;std::string&gt;(&quot;three value&quot;));
46
47    testContainer.showItem(&quot;key 2&quot;);
48    testContainer.showItem(&quot;key 3&quot;);
49    testContainer.showItem(&quot;key 2&quot;);
50
51    return 0;
52}
53cmake_minimum_required(VERSION 3.14)
54
55project(unique_ptr_string LANGUAGES CXX)
56
57set(CMAKE_INCLUDE_CURRENT_DIR ON)
58
59set(CMAKE_CXX_STANDARD 17)
60set(CMAKE_CXX_STANDARD_REQUIRED ON)
61
62add_executable(unique_ptr_string
63  main.cpp
64  unordered_map_string.h unordered_map_string.cpp
65)
66#ifndef UNORDERED_MAP_QSTRING_H
67#define UNORDERED_MAP_QSTRING_H
68
69#include &lt;QString&gt;
70
71#include &lt;memory&gt;
72#include &lt;unordered_map&gt;
73
74class UnorderedMapQString
75{
76public:
77    UnorderedMapQString() {};
78
79    std::unordered_map&lt;QString, std::unique_ptr&lt;QString&gt;&gt; container;
80
81    void addItem(QString aKey, std::unique_ptr&lt;QString&gt; aValue);
82
83    void showItem(QString aKey);
84};
85
86#endif // UNORDERED_MAP_QSTRING_H
87#include &quot;unordered_map_qstring.h&quot;
88
89#include &lt;iostream&gt;
90
91void UnorderedMapQString::addItem(QString aKey, std::unique_ptr&lt;QString&gt; aValue)
92{
93    container[aKey] = std::move(aValue);
94}
95
96void UnorderedMapQString::showItem(QString aKey)
97{
98    QString *aValue = container[aKey].get();
99    std::cout &lt;&lt; &quot;Item '&quot; &lt;&lt; aKey.toStdString() &lt;&lt; &quot;': '&quot; &lt;&lt; (*aValue).toStdString() &lt;&lt; &quot;'\n&quot;;
100}
101#include &quot;unordered_map_qstring.h&quot;
102
103#include &lt;QString&gt;
104
105#include &lt;memory&gt;
106
107int main(int argc, char *argv[])
108{
109    UnorderedMapQString testContainer;
110
111    testContainer.addItem(&quot;key 1&quot;, std::make_unique&lt;QString&gt;(&quot;one value&quot;));
112    testContainer.addItem(&quot;key 2&quot;, std::make_unique&lt;QString&gt;(&quot;two value&quot;));
113    testContainer.addItem(&quot;key 3&quot;, std::make_unique&lt;QString&gt;(&quot;three value&quot;));
114
115    testContainer.showItem(&quot;key 2&quot;);
116    testContainer.showItem(&quot;key 3&quot;);
117    testContainer.showItem(&quot;key 2&quot;);
118
119    return 0;
120}
121cmake_minimum_required(VERSION 3.14)
122
123project(unique_ptr_qstring LANGUAGES CXX)
124
125set(CMAKE_INCLUDE_CURRENT_DIR ON)
126
127set(CMAKE_CXX_STANDARD 17)
128set(CMAKE_CXX_STANDARD_REQUIRED ON)
129
130find_package(QT NAMES Qt6 Qt5 COMPONENTS Core REQUIRED)
131find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core REQUIRED)
132
133add_executable(unique_ptr_qstring
134  main.cpp
135  unordered_map_qstring.h unordered_map_qstring.cpp
136)
137target_link_libraries(unique_ptr_qstring Qt${QT_VERSION_MAJOR}::Core)
138$ make
139[ 33%] Building CXX object CMakeFiles/unique_ptr_qstring.dir/main.cpp.o
140In file included from /home/rodrigo/devel/unordered_map-qstring/main.cpp:1:
141/home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h: In constructor ‘UnorderedMapQString::UnorderedMapQString()’:
142/home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h:12:27: error: use of deleted function ‘std::unordered_map&lt;_Key, _Tp, _Hash, _Pred, _Alloc&gt;::unordered_map() [with _Key = QString; _Tp = std::unique_ptr&lt;QString&gt;; _Hash = std::hash&lt;QString&gt;; _Pred = std::equal_to&lt;QString&gt;; _Alloc = std::allocator&lt;std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt; &gt;]’
143   12 |     UnorderedMapQString() {};
144      |                           ^
145In file included from /usr/include/c++/9/unordered_map:47,
146                 from /usr/include/c++/9/functional:61,
147                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
148                 from /usr/include/c++/9/algorithm:71,
149                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:142,
150                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qchar.h:43,
151                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:48,
152                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/QString:1,
153                 from /home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h:4,
154                 from /home/rodrigo/devel/unordered_map-qstring/main.cpp:1:
155/usr/include/c++/9/bits/unordered_map.h:141:7: note: ‘std::unordered_map&lt;_Key, _Tp, _Hash, _Pred, _Alloc&gt;::unordered_map() [with _Key = QString; _Tp = std::unique_ptr&lt;QString&gt;; _Hash = std::hash&lt;QString&gt;; _Pred = std::equal_to&lt;QString&gt;; _Alloc = std::allocator&lt;std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt; &gt;]’ is implicitly deleted because the default definition would be ill-formed:
156  141 |       unordered_map() = default;
157      |       ^~~~~~~~~~~~~
158/usr/include/c++/9/bits/unordered_map.h:141:7: error: use of deleted function ‘std::_Hashtable&lt;_Key, _Value, _Alloc, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy, _Traits&gt;::_Hashtable() [with _Key = QString; _Value = std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;; _Alloc = std::allocator&lt;std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt; &gt;; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to&lt;QString&gt;; _H1 = std::hash&lt;QString&gt;; _H2 = std::__detail::_Mod_range_hashing; _Hash = std::__detail::_Default_ranged_hash; _RehashPolicy = std::__detail::_Prime_rehash_policy; _Traits = std::__detail::_Hashtable_traits&lt;true, false, true&gt;]’
159In file included from /usr/include/c++/9/unordered_map:46,
160                 from /usr/include/c++/9/functional:61,
161                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
162                 from /usr/include/c++/9/algorithm:71,
163                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:142,
164                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qchar.h:43,
165                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:48,
166                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/QString:1,
167                 from /home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h:4,
168                 from /home/rodrigo/devel/unordered_map-qstring/main.cpp:1:
169/usr/include/c++/9/bits/hashtable.h:414:7: note: ‘std::_Hashtable&lt;_Key, _Value, _Alloc, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy, _Traits&gt;::_Hashtable() [with _Key = QString; _Value = std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;; _Alloc = std::allocator&lt;std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt; &gt;; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to&lt;QString&gt;; _H1 = std::hash&lt;QString&gt;; _H2 = std::__detail::_Mod_range_hashing; _Hash = std::__detail::_Default_ranged_hash; _RehashPolicy = std::__detail::_Prime_rehash_policy; _Traits = std::__detail::_Hashtable_traits&lt;true, false, true&gt; ’ is implicitly deleted because the default definition would be ill-formed:
170  414 |       _Hashtable() = default;
171      |       ^~~~~~~~~~
172/usr/include/c++/9/bits/hashtable.h:414:7: error: use of deleted function ‘std::__detail::_Hashtable_base&lt;_Key, _Value, _ExtractKey, _Equal, _H1, _H2, _Hash, _Traits&gt;::_Hashtable_base() [with _Key = QString; _Value = std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to&lt;QString&gt;; _H1 = std::hash&lt;QString&gt;; _H2 = std::__detail::_Mod_range_hashing; _Hash = std::__detail::_Default_ranged_hash; _Traits = std::__detail::_Hashtable_traits&lt;true, false, true&gt;]’
173In file included from /usr/include/c++/9/bits/hashtable.h:35,
174                 from /usr/include/c++/9/unordered_map:46,
175                 from /usr/include/c++/9/functional:61,
176                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
177                 from /usr/include/c++/9/algorithm:71,
178                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:142,
179                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qchar.h:43,
180                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:48,
181                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/QString:1,
182                 from /home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h:4,
183                 from /home/rodrigo/devel/unordered_map-qstring/main.cpp:1:
184/usr/include/c++/9/bits/hashtable_policy.h:1822:5: note: ‘std::__detail::_Hashtable_base&lt;_Key, _Value, _ExtractKey, _Equal, _H1, _H2, _Hash, _Traits&gt;::_Hashtable_base() [with _Key = QString; _Value = std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to&lt;QString&gt;; _H1 = std::hash&lt;QString&gt;; _H2 = std::__detail::_Mod_range_hashing; _Hash = std::__detail::_Default_ranged_hash; _Traits = std::__detail::_Hashtable_traits&lt;true, false, true&gt;]’ is implicitly deleted because the default definition would be ill-formed:
185 1822 |     _Hashtable_base() = default;
186      |     ^~~~~~~~~~~~~~~
187/usr/include/c++/9/bits/hashtable_policy.h:1822:5: error: use of deleted function ‘std::__detail::_Hash_code_base&lt;_Key, _Value, _ExtractKey, _H1, _H2, std::__detail::_Default_ranged_hash, true&gt;::_Hash_code_base() [with _Key = QString; _Value = std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;; _ExtractKey = std::__detail::_Select1st; _H1 = std::hash&lt;QString&gt;; _H2 = std::__detail::_Mod_range_hashing]’
188/usr/include/c++/9/bits/hashtable_policy.h:1373:7: note: ‘std::__detail::_Hash_code_base&lt;_Key, _Value, _ExtractKey, _H1, _H2, std::__detail::_Default_ranged_hash, true&gt;::_Hash_code_base() [with _Key = QString; _Value = std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;; _ExtractKey = std::__detail::_Select1st; _H1 = std::hash&lt;QString&gt;; _H2 = std::__detail::_Mod_range_hashing]’ is implicitly deleted because the default definition would be ill-formed:
189 1373 |       _Hash_code_base() = default;
190      |       ^~~~~~~~~~~~~~~
191/usr/include/c++/9/bits/hashtable_policy.h:1373:7: error: use of deleted function ‘std::__detail::_Hashtable_ebo_helper&lt;_Nm, _Tp, true&gt;::_Hashtable_ebo_helper() [with int _Nm = 1; _Tp = std::hash&lt;QString&gt;]’
192/usr/include/c++/9/bits/hashtable_policy.h:1096:7: note: ‘std::__detail::_Hashtable_ebo_helper&lt;_Nm, _Tp, true&gt;::_Hashtable_ebo_helper() [with int _Nm = 1; _Tp = std::hash&lt;QString&gt;]’ is implicitly deleted because the default definition would be ill-formed:
193 1096 |       _Hashtable_ebo_helper() = default;
194      |       ^~~~~~~~~~~~~~~~~~~~~
195/usr/include/c++/9/bits/hashtable_policy.h:1096:7: error: use of deleted function ‘std::hash&lt;QString&gt;::hash()’
196In file included from /usr/include/c++/9/string_view:43,
197                 from /usr/include/c++/9/bits/basic_string.h:48,
198                 from /usr/include/c++/9/string:55,
199                 from /usr/include/c++/9/stdexcept:39,
200                 from /usr/include/c++/9/array:39,
201                 from /usr/include/c++/9/tuple:39,
202                 from /usr/include/c++/9/functional:54,
203                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
204                 from /usr/include/c++/9/algorithm:71,
205                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:142,
206                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qchar.h:43,
207                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:48,
208                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/QString:1,
209                 from /home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h:4,
210                 from /home/rodrigo/devel/unordered_map-qstring/main.cpp:1:
211/usr/include/c++/9/bits/functional_hash.h:101:12: note: ‘std::hash&lt;QString&gt;::hash()’ is implicitly deleted because the default definition would be ill-formed:
212  101 |     struct hash : __hash_enum&lt;_Tp&gt;
213      |            ^~~~
214/usr/include/c++/9/bits/functional_hash.h:101:12: error: no matching function for call to ‘std::__hash_enum&lt;QString, false&gt;::__hash_enum()’
215/usr/include/c++/9/bits/functional_hash.h:82:7: note: candidate: ‘std::__hash_enum&lt;_Tp, &lt;anonymous&gt; &gt;::__hash_enum(std::__hash_enum&lt;_Tp, &lt;anonymous&gt; &gt;&amp;&amp;) [with _Tp = QString; bool &lt;anonymous&gt; = false]’
216   82 |       __hash_enum(__hash_enum&amp;&amp;);
217      |       ^~~~~~~~~~~
218/usr/include/c++/9/bits/functional_hash.h:82:7: note:   candidate expects 1 argument, 0 provided
219/usr/include/c++/9/bits/functional_hash.h:101:12: error: ‘std::__hash_enum&lt;_Tp, &lt;anonymous&gt; &gt;::~__hash_enum() [with _Tp = QString; bool &lt;anonymous&gt; = false]’ is private within this context
220  101 |     struct hash : __hash_enum&lt;_Tp&gt;
221      |            ^~~~
222/usr/include/c++/9/bits/functional_hash.h:83:7: note: declared private here
223   83 |       ~__hash_enum();
224      |       ^
225In file included from /usr/include/c++/9/bits/hashtable.h:35,
226                 from /usr/include/c++/9/unordered_map:46,
227                 from /usr/include/c++/9/functional:61,
228                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
229                 from /usr/include/c++/9/algorithm:71,
230                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:142,
231                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qchar.h:43,
232                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:48,
233                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/QString:1,
234                 from /home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h:4,
235                 from /home/rodrigo/devel/unordered_map-qstring/main.cpp:1:
236/usr/include/c++/9/bits/hashtable_policy.h:1096:7: error: use of deleted function ‘std::hash&lt;QString&gt;::~hash()’
237 1096 |       _Hashtable_ebo_helper() = default;
238      |       ^~~~~~~~~~~~~~~~~~~~~
239In file included from /usr/include/c++/9/string_view:43,
240                 from /usr/include/c++/9/bits/basic_string.h:48,
241                 from /usr/include/c++/9/string:55,
242                 from /usr/include/c++/9/stdexcept:39,
243                 from /usr/include/c++/9/array:39,
244                 from /usr/include/c++/9/tuple:39,
245                 from /usr/include/c++/9/functional:54,
246                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
247                 from /usr/include/c++/9/algorithm:71,
248                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:142,
249                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qchar.h:43,
250                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:48,
251                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/QString:1,
252                 from /home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h:4,
253                 from /home/rodrigo/devel/unordered_map-qstring/main.cpp:1:
254/usr/include/c++/9/bits/functional_hash.h:101:12: note: ‘std::hash&lt;QString&gt;::~hash()’ is implicitly deleted because the default definition would be ill-formed:
255  101 |     struct hash : __hash_enum&lt;_Tp&gt;
256      |            ^~~~
257/usr/include/c++/9/bits/functional_hash.h:101:12: error: ‘std::__hash_enum&lt;_Tp, &lt;anonymous&gt; &gt;::~__hash_enum() [with _Tp = QString; bool &lt;anonymous&gt; = false]’ is private within this context
258/usr/include/c++/9/bits/functional_hash.h:83:7: note: declared private here
259   83 |       ~__hash_enum();
260      |       ^
261In file included from /usr/include/c++/9/bits/hashtable.h:35,
262                 from /usr/include/c++/9/unordered_map:46,
263                 from /usr/include/c++/9/functional:61,
264                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
265                 from /usr/include/c++/9/algorithm:71,
266                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:142,
267                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qchar.h:43,
268                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:48,
269                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/QString:1,
270                 from /home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h:4,
271                 from /home/rodrigo/devel/unordered_map-qstring/main.cpp:1:
272/usr/include/c++/9/bits/hashtable_policy.h:1373:7: error: use of deleted function ‘std::__detail::_Hashtable_ebo_helper&lt;1, std::hash&lt;QString&gt;, true&gt;::~_Hashtable_ebo_helper()’
273 1373 |       _Hash_code_base() = default;
274      |       ^~~~~~~~~~~~~~~
275/usr/include/c++/9/bits/hashtable_policy.h:1093:12: note: ‘std::__detail::_Hashtable_ebo_helper&lt;1, std::hash&lt;QString&gt;, true&gt;::~_Hashtable_ebo_helper()’ is implicitly deleted because the default definition would be ill-formed:
276 1093 |     struct _Hashtable_ebo_helper&lt;_Nm, _Tp, true&gt;
277      |            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
278/usr/include/c++/9/bits/hashtable_policy.h:1093:12: error: use of deleted function ‘std::hash&lt;QString&gt;::~hash()’
279/usr/include/c++/9/bits/hashtable_policy.h:1822:5: error: use of deleted function ‘std::__detail::_Hash_code_base&lt;QString, std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;, std::__detail::_Select1st, std::hash&lt;QString&gt;, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, true&gt;::~_Hash_code_base()’
280 1822 |     _Hashtable_base() = default;
281      |     ^~~~~~~~~~~~~~~
282/usr/include/c++/9/bits/hashtable_policy.h:1346:12: note: ‘std::__detail::_Hash_code_base&lt;QString, std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;, std::__detail::_Select1st, std::hash&lt;QString&gt;, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, true&gt;::~_Hash_code_base()’ is implicitly deleted because the default definition would be ill-formed:
283 1346 |     struct _Hash_code_base&lt;_Key, _Value, _ExtractKey, _H1, _H2,
284      |            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
285 1347 |       _Default_ranged_hash, true&gt;
286      |       ~~~~~~~~~~~~~~~~~~~~~~~~~~~
287/usr/include/c++/9/bits/hashtable_policy.h:1346:12: error: use of deleted function ‘std::__detail::_Hashtable_ebo_helper&lt;1, std::hash&lt;QString&gt;, true&gt;::~_Hashtable_ebo_helper()’
288In file included from /usr/include/c++/9/unordered_map:46,
289                 from /usr/include/c++/9/functional:61,
290                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
291                 from /usr/include/c++/9/algorithm:71,
292                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:142,
293                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qchar.h:43,
294                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:48,
295                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/QString:1,
296                 from /home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h:4,
297                 from /home/rodrigo/devel/unordered_map-qstring/main.cpp:1:
298/usr/include/c++/9/bits/hashtable.h:414:7: error: use of deleted function ‘std::__detail::_Hashtable_base&lt;QString, std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;, std::__detail::_Select1st, std::equal_to&lt;QString&gt;, std::hash&lt;QString&gt;, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Hashtable_traits&lt;true, false, true&gt; &gt;::~_Hashtable_base()’
299  414 |       _Hashtable() = default;
300      |       ^~~~~~~~~~
301In file included from /usr/include/c++/9/bits/hashtable.h:35,
302                 from /usr/include/c++/9/unordered_map:46,
303                 from /usr/include/c++/9/functional:61,
304                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
305                 from /usr/include/c++/9/algorithm:71,
306                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:142,
307                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qchar.h:43,
308                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:48,
309                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/QString:1,
310                 from /home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h:4,
311                 from /home/rodrigo/devel/unordered_map-qstring/main.cpp:1:
312/usr/include/c++/9/bits/hashtable_policy.h:1770:10: note: ‘std::__detail::_Hashtable_base&lt;QString, std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;, std::__detail::_Select1st, std::equal_to&lt;QString&gt;, std::hash&lt;QString&gt;, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Hashtable_traits&lt;true, false, true&gt; &gt;::~_Hashtable_base()’ is implicitly deleted because the default definition would be ill-formed:
313 1770 |   struct _Hashtable_base
314      |          ^~~~~~~~~~~~~~~
315/usr/include/c++/9/bits/hashtable_policy.h:1770:10: error: use of deleted function ‘std::__detail::_Hash_code_base&lt;QString, std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;, std::__detail::_Select1st, std::hash&lt;QString&gt;, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, true&gt;::~_Hash_code_base()’
316In file included from /usr/include/c++/9/unordered_map:46,
317                 from /usr/include/c++/9/functional:61,
318                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
319                 from /usr/include/c++/9/algorithm:71,
320                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:142,
321                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qchar.h:43,
322                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:48,
323                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/QString:1,
324                 from /home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h:4,
325                 from /home/rodrigo/devel/unordered_map-qstring/main.cpp:1:
326/usr/include/c++/9/bits/hashtable.h: In instantiation of ‘std::_Hashtable&lt;_Key, _Value, _Alloc, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy, _Traits&gt;::~_Hashtable() [with _Key = QString; _Value = std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;; _Alloc = std::allocator&lt;std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt; &gt;; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to&lt;QString&gt;; _H1 = std::hash&lt;QString&gt;; _H2 = std::__detail::_Mod_range_hashing; _Hash = std::__detail::_Default_ranged_hash; _RehashPolicy = std::__detail::_Prime_rehash_policy; _Traits = std::__detail::_Hashtable_traits&lt;true, false, true&gt;]’:
327/usr/include/c++/9/bits/unordered_map.h:102:11:   required from here
328/usr/include/c++/9/bits/hashtable.h:1354:5: error: use of deleted function ‘std::__detail::_Hashtable_base&lt;QString, std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;, std::__detail::_Select1st, std::equal_to&lt;QString&gt;, std::hash&lt;QString&gt;, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Hashtable_traits&lt;true, false, true&gt; &gt;::~_Hashtable_base()’
329 1354 |     }
330      |     ^
331make[2]: *** [CMakeFiles/unique_ptr_qstring.dir/build.make:63: CMakeFiles/unique_ptr_qstring.dir/main.cpp.o] Error 1
332make[1]: *** [CMakeFiles/Makefile2:76: CMakeFiles/unique_ptr_qstring.dir/all] Error 2
333make: *** [Makefile:84: all] Error 2
334
Example 3 (not working): QHash and QString qhash_qstring.h
1#ifndef UNORDERED_MAP_STRING_H
2#define UNORDERED_MAP_STRING_H
3
4#include &lt;memory&gt;
5#include &lt;string&gt;
6#include &lt;unordered_map&gt;
7
8class UnorderedMapString
9{
10public:
11    UnorderedMapString() {};
12
13    std::unordered_map&lt;std::string, std::unique_ptr&lt;std::string&gt;&gt; container;
14
15    void addItem(std::string aKey, std::unique_ptr&lt;std::string&gt; aValue);
16
17    void showItem(std::string aKey);
18};
19
20#endif // UNORDERED_MAP_STRING_H
21#include &quot;unordered_map_string.h&quot;
22
23#include &lt;iostream&gt;
24
25void UnorderedMapString::addItem(std::string aKey, std::unique_ptr&lt;std::string&gt; aValue)
26{
27    container[aKey] = std::move(aValue);
28}
29
30void UnorderedMapString::showItem(std::string aKey)
31{
32    std::string *aValue = container[aKey].get();
33    std::cout &lt;&lt; &quot;Item '&quot; &lt;&lt; aKey &lt;&lt; &quot;': '&quot; &lt;&lt; *aValue &lt;&lt; &quot;'\n&quot;;
34}
35#include &quot;unordered_map_string.h&quot;
36
37#include &lt;memory&gt;
38
39int main(int argc, char *argv[])
40{
41    UnorderedMapString testContainer;
42
43    testContainer.addItem(&quot;key 1&quot;, std::make_unique&lt;std::string&gt;(&quot;one value&quot;));
44    testContainer.addItem(&quot;key 2&quot;, std::make_unique&lt;std::string&gt;(&quot;two value&quot;));
45    testContainer.addItem(&quot;key 3&quot;, std::make_unique&lt;std::string&gt;(&quot;three value&quot;));
46
47    testContainer.showItem(&quot;key 2&quot;);
48    testContainer.showItem(&quot;key 3&quot;);
49    testContainer.showItem(&quot;key 2&quot;);
50
51    return 0;
52}
53cmake_minimum_required(VERSION 3.14)
54
55project(unique_ptr_string LANGUAGES CXX)
56
57set(CMAKE_INCLUDE_CURRENT_DIR ON)
58
59set(CMAKE_CXX_STANDARD 17)
60set(CMAKE_CXX_STANDARD_REQUIRED ON)
61
62add_executable(unique_ptr_string
63  main.cpp
64  unordered_map_string.h unordered_map_string.cpp
65)
66#ifndef UNORDERED_MAP_QSTRING_H
67#define UNORDERED_MAP_QSTRING_H
68
69#include &lt;QString&gt;
70
71#include &lt;memory&gt;
72#include &lt;unordered_map&gt;
73
74class UnorderedMapQString
75{
76public:
77    UnorderedMapQString() {};
78
79    std::unordered_map&lt;QString, std::unique_ptr&lt;QString&gt;&gt; container;
80
81    void addItem(QString aKey, std::unique_ptr&lt;QString&gt; aValue);
82
83    void showItem(QString aKey);
84};
85
86#endif // UNORDERED_MAP_QSTRING_H
87#include &quot;unordered_map_qstring.h&quot;
88
89#include &lt;iostream&gt;
90
91void UnorderedMapQString::addItem(QString aKey, std::unique_ptr&lt;QString&gt; aValue)
92{
93    container[aKey] = std::move(aValue);
94}
95
96void UnorderedMapQString::showItem(QString aKey)
97{
98    QString *aValue = container[aKey].get();
99    std::cout &lt;&lt; &quot;Item '&quot; &lt;&lt; aKey.toStdString() &lt;&lt; &quot;': '&quot; &lt;&lt; (*aValue).toStdString() &lt;&lt; &quot;'\n&quot;;
100}
101#include &quot;unordered_map_qstring.h&quot;
102
103#include &lt;QString&gt;
104
105#include &lt;memory&gt;
106
107int main(int argc, char *argv[])
108{
109    UnorderedMapQString testContainer;
110
111    testContainer.addItem(&quot;key 1&quot;, std::make_unique&lt;QString&gt;(&quot;one value&quot;));
112    testContainer.addItem(&quot;key 2&quot;, std::make_unique&lt;QString&gt;(&quot;two value&quot;));
113    testContainer.addItem(&quot;key 3&quot;, std::make_unique&lt;QString&gt;(&quot;three value&quot;));
114
115    testContainer.showItem(&quot;key 2&quot;);
116    testContainer.showItem(&quot;key 3&quot;);
117    testContainer.showItem(&quot;key 2&quot;);
118
119    return 0;
120}
121cmake_minimum_required(VERSION 3.14)
122
123project(unique_ptr_qstring LANGUAGES CXX)
124
125set(CMAKE_INCLUDE_CURRENT_DIR ON)
126
127set(CMAKE_CXX_STANDARD 17)
128set(CMAKE_CXX_STANDARD_REQUIRED ON)
129
130find_package(QT NAMES Qt6 Qt5 COMPONENTS Core REQUIRED)
131find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core REQUIRED)
132
133add_executable(unique_ptr_qstring
134  main.cpp
135  unordered_map_qstring.h unordered_map_qstring.cpp
136)
137target_link_libraries(unique_ptr_qstring Qt${QT_VERSION_MAJOR}::Core)
138$ make
139[ 33%] Building CXX object CMakeFiles/unique_ptr_qstring.dir/main.cpp.o
140In file included from /home/rodrigo/devel/unordered_map-qstring/main.cpp:1:
141/home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h: In constructor ‘UnorderedMapQString::UnorderedMapQString()’:
142/home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h:12:27: error: use of deleted function ‘std::unordered_map&lt;_Key, _Tp, _Hash, _Pred, _Alloc&gt;::unordered_map() [with _Key = QString; _Tp = std::unique_ptr&lt;QString&gt;; _Hash = std::hash&lt;QString&gt;; _Pred = std::equal_to&lt;QString&gt;; _Alloc = std::allocator&lt;std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt; &gt;]’
143   12 |     UnorderedMapQString() {};
144      |                           ^
145In file included from /usr/include/c++/9/unordered_map:47,
146                 from /usr/include/c++/9/functional:61,
147                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
148                 from /usr/include/c++/9/algorithm:71,
149                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:142,
150                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qchar.h:43,
151                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:48,
152                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/QString:1,
153                 from /home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h:4,
154                 from /home/rodrigo/devel/unordered_map-qstring/main.cpp:1:
155/usr/include/c++/9/bits/unordered_map.h:141:7: note: ‘std::unordered_map&lt;_Key, _Tp, _Hash, _Pred, _Alloc&gt;::unordered_map() [with _Key = QString; _Tp = std::unique_ptr&lt;QString&gt;; _Hash = std::hash&lt;QString&gt;; _Pred = std::equal_to&lt;QString&gt;; _Alloc = std::allocator&lt;std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt; &gt;]’ is implicitly deleted because the default definition would be ill-formed:
156  141 |       unordered_map() = default;
157      |       ^~~~~~~~~~~~~
158/usr/include/c++/9/bits/unordered_map.h:141:7: error: use of deleted function ‘std::_Hashtable&lt;_Key, _Value, _Alloc, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy, _Traits&gt;::_Hashtable() [with _Key = QString; _Value = std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;; _Alloc = std::allocator&lt;std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt; &gt;; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to&lt;QString&gt;; _H1 = std::hash&lt;QString&gt;; _H2 = std::__detail::_Mod_range_hashing; _Hash = std::__detail::_Default_ranged_hash; _RehashPolicy = std::__detail::_Prime_rehash_policy; _Traits = std::__detail::_Hashtable_traits&lt;true, false, true&gt;]’
159In file included from /usr/include/c++/9/unordered_map:46,
160                 from /usr/include/c++/9/functional:61,
161                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
162                 from /usr/include/c++/9/algorithm:71,
163                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:142,
164                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qchar.h:43,
165                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:48,
166                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/QString:1,
167                 from /home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h:4,
168                 from /home/rodrigo/devel/unordered_map-qstring/main.cpp:1:
169/usr/include/c++/9/bits/hashtable.h:414:7: note: ‘std::_Hashtable&lt;_Key, _Value, _Alloc, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy, _Traits&gt;::_Hashtable() [with _Key = QString; _Value = std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;; _Alloc = std::allocator&lt;std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt; &gt;; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to&lt;QString&gt;; _H1 = std::hash&lt;QString&gt;; _H2 = std::__detail::_Mod_range_hashing; _Hash = std::__detail::_Default_ranged_hash; _RehashPolicy = std::__detail::_Prime_rehash_policy; _Traits = std::__detail::_Hashtable_traits&lt;true, false, true&gt; ’ is implicitly deleted because the default definition would be ill-formed:
170  414 |       _Hashtable() = default;
171      |       ^~~~~~~~~~
172/usr/include/c++/9/bits/hashtable.h:414:7: error: use of deleted function ‘std::__detail::_Hashtable_base&lt;_Key, _Value, _ExtractKey, _Equal, _H1, _H2, _Hash, _Traits&gt;::_Hashtable_base() [with _Key = QString; _Value = std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to&lt;QString&gt;; _H1 = std::hash&lt;QString&gt;; _H2 = std::__detail::_Mod_range_hashing; _Hash = std::__detail::_Default_ranged_hash; _Traits = std::__detail::_Hashtable_traits&lt;true, false, true&gt;]’
173In file included from /usr/include/c++/9/bits/hashtable.h:35,
174                 from /usr/include/c++/9/unordered_map:46,
175                 from /usr/include/c++/9/functional:61,
176                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
177                 from /usr/include/c++/9/algorithm:71,
178                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:142,
179                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qchar.h:43,
180                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:48,
181                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/QString:1,
182                 from /home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h:4,
183                 from /home/rodrigo/devel/unordered_map-qstring/main.cpp:1:
184/usr/include/c++/9/bits/hashtable_policy.h:1822:5: note: ‘std::__detail::_Hashtable_base&lt;_Key, _Value, _ExtractKey, _Equal, _H1, _H2, _Hash, _Traits&gt;::_Hashtable_base() [with _Key = QString; _Value = std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to&lt;QString&gt;; _H1 = std::hash&lt;QString&gt;; _H2 = std::__detail::_Mod_range_hashing; _Hash = std::__detail::_Default_ranged_hash; _Traits = std::__detail::_Hashtable_traits&lt;true, false, true&gt;]’ is implicitly deleted because the default definition would be ill-formed:
185 1822 |     _Hashtable_base() = default;
186      |     ^~~~~~~~~~~~~~~
187/usr/include/c++/9/bits/hashtable_policy.h:1822:5: error: use of deleted function ‘std::__detail::_Hash_code_base&lt;_Key, _Value, _ExtractKey, _H1, _H2, std::__detail::_Default_ranged_hash, true&gt;::_Hash_code_base() [with _Key = QString; _Value = std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;; _ExtractKey = std::__detail::_Select1st; _H1 = std::hash&lt;QString&gt;; _H2 = std::__detail::_Mod_range_hashing]’
188/usr/include/c++/9/bits/hashtable_policy.h:1373:7: note: ‘std::__detail::_Hash_code_base&lt;_Key, _Value, _ExtractKey, _H1, _H2, std::__detail::_Default_ranged_hash, true&gt;::_Hash_code_base() [with _Key = QString; _Value = std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;; _ExtractKey = std::__detail::_Select1st; _H1 = std::hash&lt;QString&gt;; _H2 = std::__detail::_Mod_range_hashing]’ is implicitly deleted because the default definition would be ill-formed:
189 1373 |       _Hash_code_base() = default;
190      |       ^~~~~~~~~~~~~~~
191/usr/include/c++/9/bits/hashtable_policy.h:1373:7: error: use of deleted function ‘std::__detail::_Hashtable_ebo_helper&lt;_Nm, _Tp, true&gt;::_Hashtable_ebo_helper() [with int _Nm = 1; _Tp = std::hash&lt;QString&gt;]’
192/usr/include/c++/9/bits/hashtable_policy.h:1096:7: note: ‘std::__detail::_Hashtable_ebo_helper&lt;_Nm, _Tp, true&gt;::_Hashtable_ebo_helper() [with int _Nm = 1; _Tp = std::hash&lt;QString&gt;]’ is implicitly deleted because the default definition would be ill-formed:
193 1096 |       _Hashtable_ebo_helper() = default;
194      |       ^~~~~~~~~~~~~~~~~~~~~
195/usr/include/c++/9/bits/hashtable_policy.h:1096:7: error: use of deleted function ‘std::hash&lt;QString&gt;::hash()’
196In file included from /usr/include/c++/9/string_view:43,
197                 from /usr/include/c++/9/bits/basic_string.h:48,
198                 from /usr/include/c++/9/string:55,
199                 from /usr/include/c++/9/stdexcept:39,
200                 from /usr/include/c++/9/array:39,
201                 from /usr/include/c++/9/tuple:39,
202                 from /usr/include/c++/9/functional:54,
203                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
204                 from /usr/include/c++/9/algorithm:71,
205                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:142,
206                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qchar.h:43,
207                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:48,
208                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/QString:1,
209                 from /home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h:4,
210                 from /home/rodrigo/devel/unordered_map-qstring/main.cpp:1:
211/usr/include/c++/9/bits/functional_hash.h:101:12: note: ‘std::hash&lt;QString&gt;::hash()’ is implicitly deleted because the default definition would be ill-formed:
212  101 |     struct hash : __hash_enum&lt;_Tp&gt;
213      |            ^~~~
214/usr/include/c++/9/bits/functional_hash.h:101:12: error: no matching function for call to ‘std::__hash_enum&lt;QString, false&gt;::__hash_enum()’
215/usr/include/c++/9/bits/functional_hash.h:82:7: note: candidate: ‘std::__hash_enum&lt;_Tp, &lt;anonymous&gt; &gt;::__hash_enum(std::__hash_enum&lt;_Tp, &lt;anonymous&gt; &gt;&amp;&amp;) [with _Tp = QString; bool &lt;anonymous&gt; = false]’
216   82 |       __hash_enum(__hash_enum&amp;&amp;);
217      |       ^~~~~~~~~~~
218/usr/include/c++/9/bits/functional_hash.h:82:7: note:   candidate expects 1 argument, 0 provided
219/usr/include/c++/9/bits/functional_hash.h:101:12: error: ‘std::__hash_enum&lt;_Tp, &lt;anonymous&gt; &gt;::~__hash_enum() [with _Tp = QString; bool &lt;anonymous&gt; = false]’ is private within this context
220  101 |     struct hash : __hash_enum&lt;_Tp&gt;
221      |            ^~~~
222/usr/include/c++/9/bits/functional_hash.h:83:7: note: declared private here
223   83 |       ~__hash_enum();
224      |       ^
225In file included from /usr/include/c++/9/bits/hashtable.h:35,
226                 from /usr/include/c++/9/unordered_map:46,
227                 from /usr/include/c++/9/functional:61,
228                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
229                 from /usr/include/c++/9/algorithm:71,
230                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:142,
231                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qchar.h:43,
232                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:48,
233                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/QString:1,
234                 from /home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h:4,
235                 from /home/rodrigo/devel/unordered_map-qstring/main.cpp:1:
236/usr/include/c++/9/bits/hashtable_policy.h:1096:7: error: use of deleted function ‘std::hash&lt;QString&gt;::~hash()’
237 1096 |       _Hashtable_ebo_helper() = default;
238      |       ^~~~~~~~~~~~~~~~~~~~~
239In file included from /usr/include/c++/9/string_view:43,
240                 from /usr/include/c++/9/bits/basic_string.h:48,
241                 from /usr/include/c++/9/string:55,
242                 from /usr/include/c++/9/stdexcept:39,
243                 from /usr/include/c++/9/array:39,
244                 from /usr/include/c++/9/tuple:39,
245                 from /usr/include/c++/9/functional:54,
246                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
247                 from /usr/include/c++/9/algorithm:71,
248                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:142,
249                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qchar.h:43,
250                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:48,
251                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/QString:1,
252                 from /home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h:4,
253                 from /home/rodrigo/devel/unordered_map-qstring/main.cpp:1:
254/usr/include/c++/9/bits/functional_hash.h:101:12: note: ‘std::hash&lt;QString&gt;::~hash()’ is implicitly deleted because the default definition would be ill-formed:
255  101 |     struct hash : __hash_enum&lt;_Tp&gt;
256      |            ^~~~
257/usr/include/c++/9/bits/functional_hash.h:101:12: error: ‘std::__hash_enum&lt;_Tp, &lt;anonymous&gt; &gt;::~__hash_enum() [with _Tp = QString; bool &lt;anonymous&gt; = false]’ is private within this context
258/usr/include/c++/9/bits/functional_hash.h:83:7: note: declared private here
259   83 |       ~__hash_enum();
260      |       ^
261In file included from /usr/include/c++/9/bits/hashtable.h:35,
262                 from /usr/include/c++/9/unordered_map:46,
263                 from /usr/include/c++/9/functional:61,
264                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
265                 from /usr/include/c++/9/algorithm:71,
266                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:142,
267                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qchar.h:43,
268                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:48,
269                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/QString:1,
270                 from /home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h:4,
271                 from /home/rodrigo/devel/unordered_map-qstring/main.cpp:1:
272/usr/include/c++/9/bits/hashtable_policy.h:1373:7: error: use of deleted function ‘std::__detail::_Hashtable_ebo_helper&lt;1, std::hash&lt;QString&gt;, true&gt;::~_Hashtable_ebo_helper()’
273 1373 |       _Hash_code_base() = default;
274      |       ^~~~~~~~~~~~~~~
275/usr/include/c++/9/bits/hashtable_policy.h:1093:12: note: ‘std::__detail::_Hashtable_ebo_helper&lt;1, std::hash&lt;QString&gt;, true&gt;::~_Hashtable_ebo_helper()’ is implicitly deleted because the default definition would be ill-formed:
276 1093 |     struct _Hashtable_ebo_helper&lt;_Nm, _Tp, true&gt;
277      |            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
278/usr/include/c++/9/bits/hashtable_policy.h:1093:12: error: use of deleted function ‘std::hash&lt;QString&gt;::~hash()’
279/usr/include/c++/9/bits/hashtable_policy.h:1822:5: error: use of deleted function ‘std::__detail::_Hash_code_base&lt;QString, std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;, std::__detail::_Select1st, std::hash&lt;QString&gt;, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, true&gt;::~_Hash_code_base()’
280 1822 |     _Hashtable_base() = default;
281      |     ^~~~~~~~~~~~~~~
282/usr/include/c++/9/bits/hashtable_policy.h:1346:12: note: ‘std::__detail::_Hash_code_base&lt;QString, std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;, std::__detail::_Select1st, std::hash&lt;QString&gt;, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, true&gt;::~_Hash_code_base()’ is implicitly deleted because the default definition would be ill-formed:
283 1346 |     struct _Hash_code_base&lt;_Key, _Value, _ExtractKey, _H1, _H2,
284      |            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
285 1347 |       _Default_ranged_hash, true&gt;
286      |       ~~~~~~~~~~~~~~~~~~~~~~~~~~~
287/usr/include/c++/9/bits/hashtable_policy.h:1346:12: error: use of deleted function ‘std::__detail::_Hashtable_ebo_helper&lt;1, std::hash&lt;QString&gt;, true&gt;::~_Hashtable_ebo_helper()’
288In file included from /usr/include/c++/9/unordered_map:46,
289                 from /usr/include/c++/9/functional:61,
290                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
291                 from /usr/include/c++/9/algorithm:71,
292                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:142,
293                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qchar.h:43,
294                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:48,
295                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/QString:1,
296                 from /home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h:4,
297                 from /home/rodrigo/devel/unordered_map-qstring/main.cpp:1:
298/usr/include/c++/9/bits/hashtable.h:414:7: error: use of deleted function ‘std::__detail::_Hashtable_base&lt;QString, std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;, std::__detail::_Select1st, std::equal_to&lt;QString&gt;, std::hash&lt;QString&gt;, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Hashtable_traits&lt;true, false, true&gt; &gt;::~_Hashtable_base()’
299  414 |       _Hashtable() = default;
300      |       ^~~~~~~~~~
301In file included from /usr/include/c++/9/bits/hashtable.h:35,
302                 from /usr/include/c++/9/unordered_map:46,
303                 from /usr/include/c++/9/functional:61,
304                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
305                 from /usr/include/c++/9/algorithm:71,
306                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:142,
307                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qchar.h:43,
308                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:48,
309                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/QString:1,
310                 from /home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h:4,
311                 from /home/rodrigo/devel/unordered_map-qstring/main.cpp:1:
312/usr/include/c++/9/bits/hashtable_policy.h:1770:10: note: ‘std::__detail::_Hashtable_base&lt;QString, std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;, std::__detail::_Select1st, std::equal_to&lt;QString&gt;, std::hash&lt;QString&gt;, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Hashtable_traits&lt;true, false, true&gt; &gt;::~_Hashtable_base()’ is implicitly deleted because the default definition would be ill-formed:
313 1770 |   struct _Hashtable_base
314      |          ^~~~~~~~~~~~~~~
315/usr/include/c++/9/bits/hashtable_policy.h:1770:10: error: use of deleted function ‘std::__detail::_Hash_code_base&lt;QString, std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;, std::__detail::_Select1st, std::hash&lt;QString&gt;, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, true&gt;::~_Hash_code_base()’
316In file included from /usr/include/c++/9/unordered_map:46,
317                 from /usr/include/c++/9/functional:61,
318                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
319                 from /usr/include/c++/9/algorithm:71,
320                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:142,
321                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qchar.h:43,
322                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:48,
323                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/QString:1,
324                 from /home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h:4,
325                 from /home/rodrigo/devel/unordered_map-qstring/main.cpp:1:
326/usr/include/c++/9/bits/hashtable.h: In instantiation of ‘std::_Hashtable&lt;_Key, _Value, _Alloc, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy, _Traits&gt;::~_Hashtable() [with _Key = QString; _Value = std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;; _Alloc = std::allocator&lt;std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt; &gt;; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to&lt;QString&gt;; _H1 = std::hash&lt;QString&gt;; _H2 = std::__detail::_Mod_range_hashing; _Hash = std::__detail::_Default_ranged_hash; _RehashPolicy = std::__detail::_Prime_rehash_policy; _Traits = std::__detail::_Hashtable_traits&lt;true, false, true&gt;]’:
327/usr/include/c++/9/bits/unordered_map.h:102:11:   required from here
328/usr/include/c++/9/bits/hashtable.h:1354:5: error: use of deleted function ‘std::__detail::_Hashtable_base&lt;QString, std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;, std::__detail::_Select1st, std::equal_to&lt;QString&gt;, std::hash&lt;QString&gt;, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Hashtable_traits&lt;true, false, true&gt; &gt;::~_Hashtable_base()’
329 1354 |     }
330      |     ^
331make[2]: *** [CMakeFiles/unique_ptr_qstring.dir/build.make:63: CMakeFiles/unique_ptr_qstring.dir/main.cpp.o] Error 1
332make[1]: *** [CMakeFiles/Makefile2:76: CMakeFiles/unique_ptr_qstring.dir/all] Error 2
333make: *** [Makefile:84: all] Error 2
334#ifndef QHASH_QSTRING_H
335#define QHASH_QSTRING_H
336
337#include &lt;QHash&gt;
338#include &lt;QString&gt;
339
340#include &lt;memory&gt;
341
342class QHashQString
343{
344public:
345    QHashQString() {};
346
347    QHash&lt;QString, std::unique_ptr&lt;QString&gt;&gt; container;
348
349    void addItem(QString aKey, std::unique_ptr&lt;QString&gt; aValue);
350
351    void showItem(QString aKey);
352};
353
354#endif // QHASH_QSTRING_H
355
qhash_qstring.cpp
1#ifndef UNORDERED_MAP_STRING_H
2#define UNORDERED_MAP_STRING_H
3
4#include &lt;memory&gt;
5#include &lt;string&gt;
6#include &lt;unordered_map&gt;
7
8class UnorderedMapString
9{
10public:
11    UnorderedMapString() {};
12
13    std::unordered_map&lt;std::string, std::unique_ptr&lt;std::string&gt;&gt; container;
14
15    void addItem(std::string aKey, std::unique_ptr&lt;std::string&gt; aValue);
16
17    void showItem(std::string aKey);
18};
19
20#endif // UNORDERED_MAP_STRING_H
21#include &quot;unordered_map_string.h&quot;
22
23#include &lt;iostream&gt;
24
25void UnorderedMapString::addItem(std::string aKey, std::unique_ptr&lt;std::string&gt; aValue)
26{
27    container[aKey] = std::move(aValue);
28}
29
30void UnorderedMapString::showItem(std::string aKey)
31{
32    std::string *aValue = container[aKey].get();
33    std::cout &lt;&lt; &quot;Item '&quot; &lt;&lt; aKey &lt;&lt; &quot;': '&quot; &lt;&lt; *aValue &lt;&lt; &quot;'\n&quot;;
34}
35#include &quot;unordered_map_string.h&quot;
36
37#include &lt;memory&gt;
38
39int main(int argc, char *argv[])
40{
41    UnorderedMapString testContainer;
42
43    testContainer.addItem(&quot;key 1&quot;, std::make_unique&lt;std::string&gt;(&quot;one value&quot;));
44    testContainer.addItem(&quot;key 2&quot;, std::make_unique&lt;std::string&gt;(&quot;two value&quot;));
45    testContainer.addItem(&quot;key 3&quot;, std::make_unique&lt;std::string&gt;(&quot;three value&quot;));
46
47    testContainer.showItem(&quot;key 2&quot;);
48    testContainer.showItem(&quot;key 3&quot;);
49    testContainer.showItem(&quot;key 2&quot;);
50
51    return 0;
52}
53cmake_minimum_required(VERSION 3.14)
54
55project(unique_ptr_string LANGUAGES CXX)
56
57set(CMAKE_INCLUDE_CURRENT_DIR ON)
58
59set(CMAKE_CXX_STANDARD 17)
60set(CMAKE_CXX_STANDARD_REQUIRED ON)
61
62add_executable(unique_ptr_string
63  main.cpp
64  unordered_map_string.h unordered_map_string.cpp
65)
66#ifndef UNORDERED_MAP_QSTRING_H
67#define UNORDERED_MAP_QSTRING_H
68
69#include &lt;QString&gt;
70
71#include &lt;memory&gt;
72#include &lt;unordered_map&gt;
73
74class UnorderedMapQString
75{
76public:
77    UnorderedMapQString() {};
78
79    std::unordered_map&lt;QString, std::unique_ptr&lt;QString&gt;&gt; container;
80
81    void addItem(QString aKey, std::unique_ptr&lt;QString&gt; aValue);
82
83    void showItem(QString aKey);
84};
85
86#endif // UNORDERED_MAP_QSTRING_H
87#include &quot;unordered_map_qstring.h&quot;
88
89#include &lt;iostream&gt;
90
91void UnorderedMapQString::addItem(QString aKey, std::unique_ptr&lt;QString&gt; aValue)
92{
93    container[aKey] = std::move(aValue);
94}
95
96void UnorderedMapQString::showItem(QString aKey)
97{
98    QString *aValue = container[aKey].get();
99    std::cout &lt;&lt; &quot;Item '&quot; &lt;&lt; aKey.toStdString() &lt;&lt; &quot;': '&quot; &lt;&lt; (*aValue).toStdString() &lt;&lt; &quot;'\n&quot;;
100}
101#include &quot;unordered_map_qstring.h&quot;
102
103#include &lt;QString&gt;
104
105#include &lt;memory&gt;
106
107int main(int argc, char *argv[])
108{
109    UnorderedMapQString testContainer;
110
111    testContainer.addItem(&quot;key 1&quot;, std::make_unique&lt;QString&gt;(&quot;one value&quot;));
112    testContainer.addItem(&quot;key 2&quot;, std::make_unique&lt;QString&gt;(&quot;two value&quot;));
113    testContainer.addItem(&quot;key 3&quot;, std::make_unique&lt;QString&gt;(&quot;three value&quot;));
114
115    testContainer.showItem(&quot;key 2&quot;);
116    testContainer.showItem(&quot;key 3&quot;);
117    testContainer.showItem(&quot;key 2&quot;);
118
119    return 0;
120}
121cmake_minimum_required(VERSION 3.14)
122
123project(unique_ptr_qstring LANGUAGES CXX)
124
125set(CMAKE_INCLUDE_CURRENT_DIR ON)
126
127set(CMAKE_CXX_STANDARD 17)
128set(CMAKE_CXX_STANDARD_REQUIRED ON)
129
130find_package(QT NAMES Qt6 Qt5 COMPONENTS Core REQUIRED)
131find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core REQUIRED)
132
133add_executable(unique_ptr_qstring
134  main.cpp
135  unordered_map_qstring.h unordered_map_qstring.cpp
136)
137target_link_libraries(unique_ptr_qstring Qt${QT_VERSION_MAJOR}::Core)
138$ make
139[ 33%] Building CXX object CMakeFiles/unique_ptr_qstring.dir/main.cpp.o
140In file included from /home/rodrigo/devel/unordered_map-qstring/main.cpp:1:
141/home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h: In constructor ‘UnorderedMapQString::UnorderedMapQString()’:
142/home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h:12:27: error: use of deleted function ‘std::unordered_map&lt;_Key, _Tp, _Hash, _Pred, _Alloc&gt;::unordered_map() [with _Key = QString; _Tp = std::unique_ptr&lt;QString&gt;; _Hash = std::hash&lt;QString&gt;; _Pred = std::equal_to&lt;QString&gt;; _Alloc = std::allocator&lt;std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt; &gt;]’
143   12 |     UnorderedMapQString() {};
144      |                           ^
145In file included from /usr/include/c++/9/unordered_map:47,
146                 from /usr/include/c++/9/functional:61,
147                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
148                 from /usr/include/c++/9/algorithm:71,
149                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:142,
150                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qchar.h:43,
151                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:48,
152                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/QString:1,
153                 from /home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h:4,
154                 from /home/rodrigo/devel/unordered_map-qstring/main.cpp:1:
155/usr/include/c++/9/bits/unordered_map.h:141:7: note: ‘std::unordered_map&lt;_Key, _Tp, _Hash, _Pred, _Alloc&gt;::unordered_map() [with _Key = QString; _Tp = std::unique_ptr&lt;QString&gt;; _Hash = std::hash&lt;QString&gt;; _Pred = std::equal_to&lt;QString&gt;; _Alloc = std::allocator&lt;std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt; &gt;]’ is implicitly deleted because the default definition would be ill-formed:
156  141 |       unordered_map() = default;
157      |       ^~~~~~~~~~~~~
158/usr/include/c++/9/bits/unordered_map.h:141:7: error: use of deleted function ‘std::_Hashtable&lt;_Key, _Value, _Alloc, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy, _Traits&gt;::_Hashtable() [with _Key = QString; _Value = std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;; _Alloc = std::allocator&lt;std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt; &gt;; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to&lt;QString&gt;; _H1 = std::hash&lt;QString&gt;; _H2 = std::__detail::_Mod_range_hashing; _Hash = std::__detail::_Default_ranged_hash; _RehashPolicy = std::__detail::_Prime_rehash_policy; _Traits = std::__detail::_Hashtable_traits&lt;true, false, true&gt;]’
159In file included from /usr/include/c++/9/unordered_map:46,
160                 from /usr/include/c++/9/functional:61,
161                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
162                 from /usr/include/c++/9/algorithm:71,
163                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:142,
164                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qchar.h:43,
165                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:48,
166                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/QString:1,
167                 from /home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h:4,
168                 from /home/rodrigo/devel/unordered_map-qstring/main.cpp:1:
169/usr/include/c++/9/bits/hashtable.h:414:7: note: ‘std::_Hashtable&lt;_Key, _Value, _Alloc, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy, _Traits&gt;::_Hashtable() [with _Key = QString; _Value = std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;; _Alloc = std::allocator&lt;std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt; &gt;; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to&lt;QString&gt;; _H1 = std::hash&lt;QString&gt;; _H2 = std::__detail::_Mod_range_hashing; _Hash = std::__detail::_Default_ranged_hash; _RehashPolicy = std::__detail::_Prime_rehash_policy; _Traits = std::__detail::_Hashtable_traits&lt;true, false, true&gt; ’ is implicitly deleted because the default definition would be ill-formed:
170  414 |       _Hashtable() = default;
171      |       ^~~~~~~~~~
172/usr/include/c++/9/bits/hashtable.h:414:7: error: use of deleted function ‘std::__detail::_Hashtable_base&lt;_Key, _Value, _ExtractKey, _Equal, _H1, _H2, _Hash, _Traits&gt;::_Hashtable_base() [with _Key = QString; _Value = std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to&lt;QString&gt;; _H1 = std::hash&lt;QString&gt;; _H2 = std::__detail::_Mod_range_hashing; _Hash = std::__detail::_Default_ranged_hash; _Traits = std::__detail::_Hashtable_traits&lt;true, false, true&gt;]’
173In file included from /usr/include/c++/9/bits/hashtable.h:35,
174                 from /usr/include/c++/9/unordered_map:46,
175                 from /usr/include/c++/9/functional:61,
176                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
177                 from /usr/include/c++/9/algorithm:71,
178                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:142,
179                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qchar.h:43,
180                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:48,
181                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/QString:1,
182                 from /home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h:4,
183                 from /home/rodrigo/devel/unordered_map-qstring/main.cpp:1:
184/usr/include/c++/9/bits/hashtable_policy.h:1822:5: note: ‘std::__detail::_Hashtable_base&lt;_Key, _Value, _ExtractKey, _Equal, _H1, _H2, _Hash, _Traits&gt;::_Hashtable_base() [with _Key = QString; _Value = std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to&lt;QString&gt;; _H1 = std::hash&lt;QString&gt;; _H2 = std::__detail::_Mod_range_hashing; _Hash = std::__detail::_Default_ranged_hash; _Traits = std::__detail::_Hashtable_traits&lt;true, false, true&gt;]’ is implicitly deleted because the default definition would be ill-formed:
185 1822 |     _Hashtable_base() = default;
186      |     ^~~~~~~~~~~~~~~
187/usr/include/c++/9/bits/hashtable_policy.h:1822:5: error: use of deleted function ‘std::__detail::_Hash_code_base&lt;_Key, _Value, _ExtractKey, _H1, _H2, std::__detail::_Default_ranged_hash, true&gt;::_Hash_code_base() [with _Key = QString; _Value = std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;; _ExtractKey = std::__detail::_Select1st; _H1 = std::hash&lt;QString&gt;; _H2 = std::__detail::_Mod_range_hashing]’
188/usr/include/c++/9/bits/hashtable_policy.h:1373:7: note: ‘std::__detail::_Hash_code_base&lt;_Key, _Value, _ExtractKey, _H1, _H2, std::__detail::_Default_ranged_hash, true&gt;::_Hash_code_base() [with _Key = QString; _Value = std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;; _ExtractKey = std::__detail::_Select1st; _H1 = std::hash&lt;QString&gt;; _H2 = std::__detail::_Mod_range_hashing]’ is implicitly deleted because the default definition would be ill-formed:
189 1373 |       _Hash_code_base() = default;
190      |       ^~~~~~~~~~~~~~~
191/usr/include/c++/9/bits/hashtable_policy.h:1373:7: error: use of deleted function ‘std::__detail::_Hashtable_ebo_helper&lt;_Nm, _Tp, true&gt;::_Hashtable_ebo_helper() [with int _Nm = 1; _Tp = std::hash&lt;QString&gt;]’
192/usr/include/c++/9/bits/hashtable_policy.h:1096:7: note: ‘std::__detail::_Hashtable_ebo_helper&lt;_Nm, _Tp, true&gt;::_Hashtable_ebo_helper() [with int _Nm = 1; _Tp = std::hash&lt;QString&gt;]’ is implicitly deleted because the default definition would be ill-formed:
193 1096 |       _Hashtable_ebo_helper() = default;
194      |       ^~~~~~~~~~~~~~~~~~~~~
195/usr/include/c++/9/bits/hashtable_policy.h:1096:7: error: use of deleted function ‘std::hash&lt;QString&gt;::hash()’
196In file included from /usr/include/c++/9/string_view:43,
197                 from /usr/include/c++/9/bits/basic_string.h:48,
198                 from /usr/include/c++/9/string:55,
199                 from /usr/include/c++/9/stdexcept:39,
200                 from /usr/include/c++/9/array:39,
201                 from /usr/include/c++/9/tuple:39,
202                 from /usr/include/c++/9/functional:54,
203                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
204                 from /usr/include/c++/9/algorithm:71,
205                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:142,
206                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qchar.h:43,
207                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:48,
208                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/QString:1,
209                 from /home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h:4,
210                 from /home/rodrigo/devel/unordered_map-qstring/main.cpp:1:
211/usr/include/c++/9/bits/functional_hash.h:101:12: note: ‘std::hash&lt;QString&gt;::hash()’ is implicitly deleted because the default definition would be ill-formed:
212  101 |     struct hash : __hash_enum&lt;_Tp&gt;
213      |            ^~~~
214/usr/include/c++/9/bits/functional_hash.h:101:12: error: no matching function for call to ‘std::__hash_enum&lt;QString, false&gt;::__hash_enum()’
215/usr/include/c++/9/bits/functional_hash.h:82:7: note: candidate: ‘std::__hash_enum&lt;_Tp, &lt;anonymous&gt; &gt;::__hash_enum(std::__hash_enum&lt;_Tp, &lt;anonymous&gt; &gt;&amp;&amp;) [with _Tp = QString; bool &lt;anonymous&gt; = false]’
216   82 |       __hash_enum(__hash_enum&amp;&amp;);
217      |       ^~~~~~~~~~~
218/usr/include/c++/9/bits/functional_hash.h:82:7: note:   candidate expects 1 argument, 0 provided
219/usr/include/c++/9/bits/functional_hash.h:101:12: error: ‘std::__hash_enum&lt;_Tp, &lt;anonymous&gt; &gt;::~__hash_enum() [with _Tp = QString; bool &lt;anonymous&gt; = false]’ is private within this context
220  101 |     struct hash : __hash_enum&lt;_Tp&gt;
221      |            ^~~~
222/usr/include/c++/9/bits/functional_hash.h:83:7: note: declared private here
223   83 |       ~__hash_enum();
224      |       ^
225In file included from /usr/include/c++/9/bits/hashtable.h:35,
226                 from /usr/include/c++/9/unordered_map:46,
227                 from /usr/include/c++/9/functional:61,
228                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
229                 from /usr/include/c++/9/algorithm:71,
230                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:142,
231                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qchar.h:43,
232                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:48,
233                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/QString:1,
234                 from /home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h:4,
235                 from /home/rodrigo/devel/unordered_map-qstring/main.cpp:1:
236/usr/include/c++/9/bits/hashtable_policy.h:1096:7: error: use of deleted function ‘std::hash&lt;QString&gt;::~hash()’
237 1096 |       _Hashtable_ebo_helper() = default;
238      |       ^~~~~~~~~~~~~~~~~~~~~
239In file included from /usr/include/c++/9/string_view:43,
240                 from /usr/include/c++/9/bits/basic_string.h:48,
241                 from /usr/include/c++/9/string:55,
242                 from /usr/include/c++/9/stdexcept:39,
243                 from /usr/include/c++/9/array:39,
244                 from /usr/include/c++/9/tuple:39,
245                 from /usr/include/c++/9/functional:54,
246                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
247                 from /usr/include/c++/9/algorithm:71,
248                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:142,
249                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qchar.h:43,
250                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:48,
251                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/QString:1,
252                 from /home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h:4,
253                 from /home/rodrigo/devel/unordered_map-qstring/main.cpp:1:
254/usr/include/c++/9/bits/functional_hash.h:101:12: note: ‘std::hash&lt;QString&gt;::~hash()’ is implicitly deleted because the default definition would be ill-formed:
255  101 |     struct hash : __hash_enum&lt;_Tp&gt;
256      |            ^~~~
257/usr/include/c++/9/bits/functional_hash.h:101:12: error: ‘std::__hash_enum&lt;_Tp, &lt;anonymous&gt; &gt;::~__hash_enum() [with _Tp = QString; bool &lt;anonymous&gt; = false]’ is private within this context
258/usr/include/c++/9/bits/functional_hash.h:83:7: note: declared private here
259   83 |       ~__hash_enum();
260      |       ^
261In file included from /usr/include/c++/9/bits/hashtable.h:35,
262                 from /usr/include/c++/9/unordered_map:46,
263                 from /usr/include/c++/9/functional:61,
264                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
265                 from /usr/include/c++/9/algorithm:71,
266                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:142,
267                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qchar.h:43,
268                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:48,
269                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/QString:1,
270                 from /home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h:4,
271                 from /home/rodrigo/devel/unordered_map-qstring/main.cpp:1:
272/usr/include/c++/9/bits/hashtable_policy.h:1373:7: error: use of deleted function ‘std::__detail::_Hashtable_ebo_helper&lt;1, std::hash&lt;QString&gt;, true&gt;::~_Hashtable_ebo_helper()’
273 1373 |       _Hash_code_base() = default;
274      |       ^~~~~~~~~~~~~~~
275/usr/include/c++/9/bits/hashtable_policy.h:1093:12: note: ‘std::__detail::_Hashtable_ebo_helper&lt;1, std::hash&lt;QString&gt;, true&gt;::~_Hashtable_ebo_helper()’ is implicitly deleted because the default definition would be ill-formed:
276 1093 |     struct _Hashtable_ebo_helper&lt;_Nm, _Tp, true&gt;
277      |            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
278/usr/include/c++/9/bits/hashtable_policy.h:1093:12: error: use of deleted function ‘std::hash&lt;QString&gt;::~hash()’
279/usr/include/c++/9/bits/hashtable_policy.h:1822:5: error: use of deleted function ‘std::__detail::_Hash_code_base&lt;QString, std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;, std::__detail::_Select1st, std::hash&lt;QString&gt;, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, true&gt;::~_Hash_code_base()’
280 1822 |     _Hashtable_base() = default;
281      |     ^~~~~~~~~~~~~~~
282/usr/include/c++/9/bits/hashtable_policy.h:1346:12: note: ‘std::__detail::_Hash_code_base&lt;QString, std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;, std::__detail::_Select1st, std::hash&lt;QString&gt;, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, true&gt;::~_Hash_code_base()’ is implicitly deleted because the default definition would be ill-formed:
283 1346 |     struct _Hash_code_base&lt;_Key, _Value, _ExtractKey, _H1, _H2,
284      |            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
285 1347 |       _Default_ranged_hash, true&gt;
286      |       ~~~~~~~~~~~~~~~~~~~~~~~~~~~
287/usr/include/c++/9/bits/hashtable_policy.h:1346:12: error: use of deleted function ‘std::__detail::_Hashtable_ebo_helper&lt;1, std::hash&lt;QString&gt;, true&gt;::~_Hashtable_ebo_helper()’
288In file included from /usr/include/c++/9/unordered_map:46,
289                 from /usr/include/c++/9/functional:61,
290                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
291                 from /usr/include/c++/9/algorithm:71,
292                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:142,
293                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qchar.h:43,
294                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:48,
295                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/QString:1,
296                 from /home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h:4,
297                 from /home/rodrigo/devel/unordered_map-qstring/main.cpp:1:
298/usr/include/c++/9/bits/hashtable.h:414:7: error: use of deleted function ‘std::__detail::_Hashtable_base&lt;QString, std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;, std::__detail::_Select1st, std::equal_to&lt;QString&gt;, std::hash&lt;QString&gt;, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Hashtable_traits&lt;true, false, true&gt; &gt;::~_Hashtable_base()’
299  414 |       _Hashtable() = default;
300      |       ^~~~~~~~~~
301In file included from /usr/include/c++/9/bits/hashtable.h:35,
302                 from /usr/include/c++/9/unordered_map:46,
303                 from /usr/include/c++/9/functional:61,
304                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
305                 from /usr/include/c++/9/algorithm:71,
306                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:142,
307                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qchar.h:43,
308                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:48,
309                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/QString:1,
310                 from /home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h:4,
311                 from /home/rodrigo/devel/unordered_map-qstring/main.cpp:1:
312/usr/include/c++/9/bits/hashtable_policy.h:1770:10: note: ‘std::__detail::_Hashtable_base&lt;QString, std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;, std::__detail::_Select1st, std::equal_to&lt;QString&gt;, std::hash&lt;QString&gt;, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Hashtable_traits&lt;true, false, true&gt; &gt;::~_Hashtable_base()’ is implicitly deleted because the default definition would be ill-formed:
313 1770 |   struct _Hashtable_base
314      |          ^~~~~~~~~~~~~~~
315/usr/include/c++/9/bits/hashtable_policy.h:1770:10: error: use of deleted function ‘std::__detail::_Hash_code_base&lt;QString, std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;, std::__detail::_Select1st, std::hash&lt;QString&gt;, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, true&gt;::~_Hash_code_base()’
316In file included from /usr/include/c++/9/unordered_map:46,
317                 from /usr/include/c++/9/functional:61,
318                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
319                 from /usr/include/c++/9/algorithm:71,
320                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:142,
321                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qchar.h:43,
322                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:48,
323                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/QString:1,
324                 from /home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h:4,
325                 from /home/rodrigo/devel/unordered_map-qstring/main.cpp:1:
326/usr/include/c++/9/bits/hashtable.h: In instantiation of ‘std::_Hashtable&lt;_Key, _Value, _Alloc, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy, _Traits&gt;::~_Hashtable() [with _Key = QString; _Value = std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;; _Alloc = std::allocator&lt;std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt; &gt;; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to&lt;QString&gt;; _H1 = std::hash&lt;QString&gt;; _H2 = std::__detail::_Mod_range_hashing; _Hash = std::__detail::_Default_ranged_hash; _RehashPolicy = std::__detail::_Prime_rehash_policy; _Traits = std::__detail::_Hashtable_traits&lt;true, false, true&gt;]’:
327/usr/include/c++/9/bits/unordered_map.h:102:11:   required from here
328/usr/include/c++/9/bits/hashtable.h:1354:5: error: use of deleted function ‘std::__detail::_Hashtable_base&lt;QString, std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;, std::__detail::_Select1st, std::equal_to&lt;QString&gt;, std::hash&lt;QString&gt;, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Hashtable_traits&lt;true, false, true&gt; &gt;::~_Hashtable_base()’
329 1354 |     }
330      |     ^
331make[2]: *** [CMakeFiles/unique_ptr_qstring.dir/build.make:63: CMakeFiles/unique_ptr_qstring.dir/main.cpp.o] Error 1
332make[1]: *** [CMakeFiles/Makefile2:76: CMakeFiles/unique_ptr_qstring.dir/all] Error 2
333make: *** [Makefile:84: all] Error 2
334#ifndef QHASH_QSTRING_H
335#define QHASH_QSTRING_H
336
337#include &lt;QHash&gt;
338#include &lt;QString&gt;
339
340#include &lt;memory&gt;
341
342class QHashQString
343{
344public:
345    QHashQString() {};
346
347    QHash&lt;QString, std::unique_ptr&lt;QString&gt;&gt; container;
348
349    void addItem(QString aKey, std::unique_ptr&lt;QString&gt; aValue);
350
351    void showItem(QString aKey);
352};
353
354#endif // QHASH_QSTRING_H
355#include &quot;qhash_qstring.h&quot;
356
357#include &lt;iostream&gt;
358
359void QHashQString::addItem(QString aKey, std::unique_ptr&lt;QString&gt; aValue)
360{
361    container[aKey] = std::move(aValue);
362}
363
364void QHashQString::showItem(QString aKey)
365{
366    QString *aValue = container[aKey].get();
367    std::cout &lt;&lt; &quot;Item '&quot; &lt;&lt; aKey.toStdString() &lt;&lt; &quot;': '&quot; &lt;&lt; (*aValue).toStdString() &lt;&lt; &quot;'\n&quot;;
368}
369
main.cpp
1#ifndef UNORDERED_MAP_STRING_H
2#define UNORDERED_MAP_STRING_H
3
4#include &lt;memory&gt;
5#include &lt;string&gt;
6#include &lt;unordered_map&gt;
7
8class UnorderedMapString
9{
10public:
11    UnorderedMapString() {};
12
13    std::unordered_map&lt;std::string, std::unique_ptr&lt;std::string&gt;&gt; container;
14
15    void addItem(std::string aKey, std::unique_ptr&lt;std::string&gt; aValue);
16
17    void showItem(std::string aKey);
18};
19
20#endif // UNORDERED_MAP_STRING_H
21#include &quot;unordered_map_string.h&quot;
22
23#include &lt;iostream&gt;
24
25void UnorderedMapString::addItem(std::string aKey, std::unique_ptr&lt;std::string&gt; aValue)
26{
27    container[aKey] = std::move(aValue);
28}
29
30void UnorderedMapString::showItem(std::string aKey)
31{
32    std::string *aValue = container[aKey].get();
33    std::cout &lt;&lt; &quot;Item '&quot; &lt;&lt; aKey &lt;&lt; &quot;': '&quot; &lt;&lt; *aValue &lt;&lt; &quot;'\n&quot;;
34}
35#include &quot;unordered_map_string.h&quot;
36
37#include &lt;memory&gt;
38
39int main(int argc, char *argv[])
40{
41    UnorderedMapString testContainer;
42
43    testContainer.addItem(&quot;key 1&quot;, std::make_unique&lt;std::string&gt;(&quot;one value&quot;));
44    testContainer.addItem(&quot;key 2&quot;, std::make_unique&lt;std::string&gt;(&quot;two value&quot;));
45    testContainer.addItem(&quot;key 3&quot;, std::make_unique&lt;std::string&gt;(&quot;three value&quot;));
46
47    testContainer.showItem(&quot;key 2&quot;);
48    testContainer.showItem(&quot;key 3&quot;);
49    testContainer.showItem(&quot;key 2&quot;);
50
51    return 0;
52}
53cmake_minimum_required(VERSION 3.14)
54
55project(unique_ptr_string LANGUAGES CXX)
56
57set(CMAKE_INCLUDE_CURRENT_DIR ON)
58
59set(CMAKE_CXX_STANDARD 17)
60set(CMAKE_CXX_STANDARD_REQUIRED ON)
61
62add_executable(unique_ptr_string
63  main.cpp
64  unordered_map_string.h unordered_map_string.cpp
65)
66#ifndef UNORDERED_MAP_QSTRING_H
67#define UNORDERED_MAP_QSTRING_H
68
69#include &lt;QString&gt;
70
71#include &lt;memory&gt;
72#include &lt;unordered_map&gt;
73
74class UnorderedMapQString
75{
76public:
77    UnorderedMapQString() {};
78
79    std::unordered_map&lt;QString, std::unique_ptr&lt;QString&gt;&gt; container;
80
81    void addItem(QString aKey, std::unique_ptr&lt;QString&gt; aValue);
82
83    void showItem(QString aKey);
84};
85
86#endif // UNORDERED_MAP_QSTRING_H
87#include &quot;unordered_map_qstring.h&quot;
88
89#include &lt;iostream&gt;
90
91void UnorderedMapQString::addItem(QString aKey, std::unique_ptr&lt;QString&gt; aValue)
92{
93    container[aKey] = std::move(aValue);
94}
95
96void UnorderedMapQString::showItem(QString aKey)
97{
98    QString *aValue = container[aKey].get();
99    std::cout &lt;&lt; &quot;Item '&quot; &lt;&lt; aKey.toStdString() &lt;&lt; &quot;': '&quot; &lt;&lt; (*aValue).toStdString() &lt;&lt; &quot;'\n&quot;;
100}
101#include &quot;unordered_map_qstring.h&quot;
102
103#include &lt;QString&gt;
104
105#include &lt;memory&gt;
106
107int main(int argc, char *argv[])
108{
109    UnorderedMapQString testContainer;
110
111    testContainer.addItem(&quot;key 1&quot;, std::make_unique&lt;QString&gt;(&quot;one value&quot;));
112    testContainer.addItem(&quot;key 2&quot;, std::make_unique&lt;QString&gt;(&quot;two value&quot;));
113    testContainer.addItem(&quot;key 3&quot;, std::make_unique&lt;QString&gt;(&quot;three value&quot;));
114
115    testContainer.showItem(&quot;key 2&quot;);
116    testContainer.showItem(&quot;key 3&quot;);
117    testContainer.showItem(&quot;key 2&quot;);
118
119    return 0;
120}
121cmake_minimum_required(VERSION 3.14)
122
123project(unique_ptr_qstring LANGUAGES CXX)
124
125set(CMAKE_INCLUDE_CURRENT_DIR ON)
126
127set(CMAKE_CXX_STANDARD 17)
128set(CMAKE_CXX_STANDARD_REQUIRED ON)
129
130find_package(QT NAMES Qt6 Qt5 COMPONENTS Core REQUIRED)
131find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core REQUIRED)
132
133add_executable(unique_ptr_qstring
134  main.cpp
135  unordered_map_qstring.h unordered_map_qstring.cpp
136)
137target_link_libraries(unique_ptr_qstring Qt${QT_VERSION_MAJOR}::Core)
138$ make
139[ 33%] Building CXX object CMakeFiles/unique_ptr_qstring.dir/main.cpp.o
140In file included from /home/rodrigo/devel/unordered_map-qstring/main.cpp:1:
141/home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h: In constructor ‘UnorderedMapQString::UnorderedMapQString()’:
142/home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h:12:27: error: use of deleted function ‘std::unordered_map&lt;_Key, _Tp, _Hash, _Pred, _Alloc&gt;::unordered_map() [with _Key = QString; _Tp = std::unique_ptr&lt;QString&gt;; _Hash = std::hash&lt;QString&gt;; _Pred = std::equal_to&lt;QString&gt;; _Alloc = std::allocator&lt;std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt; &gt;]’
143   12 |     UnorderedMapQString() {};
144      |                           ^
145In file included from /usr/include/c++/9/unordered_map:47,
146                 from /usr/include/c++/9/functional:61,
147                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
148                 from /usr/include/c++/9/algorithm:71,
149                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:142,
150                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qchar.h:43,
151                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:48,
152                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/QString:1,
153                 from /home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h:4,
154                 from /home/rodrigo/devel/unordered_map-qstring/main.cpp:1:
155/usr/include/c++/9/bits/unordered_map.h:141:7: note: ‘std::unordered_map&lt;_Key, _Tp, _Hash, _Pred, _Alloc&gt;::unordered_map() [with _Key = QString; _Tp = std::unique_ptr&lt;QString&gt;; _Hash = std::hash&lt;QString&gt;; _Pred = std::equal_to&lt;QString&gt;; _Alloc = std::allocator&lt;std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt; &gt;]’ is implicitly deleted because the default definition would be ill-formed:
156  141 |       unordered_map() = default;
157      |       ^~~~~~~~~~~~~
158/usr/include/c++/9/bits/unordered_map.h:141:7: error: use of deleted function ‘std::_Hashtable&lt;_Key, _Value, _Alloc, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy, _Traits&gt;::_Hashtable() [with _Key = QString; _Value = std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;; _Alloc = std::allocator&lt;std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt; &gt;; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to&lt;QString&gt;; _H1 = std::hash&lt;QString&gt;; _H2 = std::__detail::_Mod_range_hashing; _Hash = std::__detail::_Default_ranged_hash; _RehashPolicy = std::__detail::_Prime_rehash_policy; _Traits = std::__detail::_Hashtable_traits&lt;true, false, true&gt;]’
159In file included from /usr/include/c++/9/unordered_map:46,
160                 from /usr/include/c++/9/functional:61,
161                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
162                 from /usr/include/c++/9/algorithm:71,
163                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:142,
164                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qchar.h:43,
165                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:48,
166                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/QString:1,
167                 from /home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h:4,
168                 from /home/rodrigo/devel/unordered_map-qstring/main.cpp:1:
169/usr/include/c++/9/bits/hashtable.h:414:7: note: ‘std::_Hashtable&lt;_Key, _Value, _Alloc, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy, _Traits&gt;::_Hashtable() [with _Key = QString; _Value = std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;; _Alloc = std::allocator&lt;std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt; &gt;; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to&lt;QString&gt;; _H1 = std::hash&lt;QString&gt;; _H2 = std::__detail::_Mod_range_hashing; _Hash = std::__detail::_Default_ranged_hash; _RehashPolicy = std::__detail::_Prime_rehash_policy; _Traits = std::__detail::_Hashtable_traits&lt;true, false, true&gt; ’ is implicitly deleted because the default definition would be ill-formed:
170  414 |       _Hashtable() = default;
171      |       ^~~~~~~~~~
172/usr/include/c++/9/bits/hashtable.h:414:7: error: use of deleted function ‘std::__detail::_Hashtable_base&lt;_Key, _Value, _ExtractKey, _Equal, _H1, _H2, _Hash, _Traits&gt;::_Hashtable_base() [with _Key = QString; _Value = std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to&lt;QString&gt;; _H1 = std::hash&lt;QString&gt;; _H2 = std::__detail::_Mod_range_hashing; _Hash = std::__detail::_Default_ranged_hash; _Traits = std::__detail::_Hashtable_traits&lt;true, false, true&gt;]’
173In file included from /usr/include/c++/9/bits/hashtable.h:35,
174                 from /usr/include/c++/9/unordered_map:46,
175                 from /usr/include/c++/9/functional:61,
176                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
177                 from /usr/include/c++/9/algorithm:71,
178                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:142,
179                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qchar.h:43,
180                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:48,
181                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/QString:1,
182                 from /home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h:4,
183                 from /home/rodrigo/devel/unordered_map-qstring/main.cpp:1:
184/usr/include/c++/9/bits/hashtable_policy.h:1822:5: note: ‘std::__detail::_Hashtable_base&lt;_Key, _Value, _ExtractKey, _Equal, _H1, _H2, _Hash, _Traits&gt;::_Hashtable_base() [with _Key = QString; _Value = std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to&lt;QString&gt;; _H1 = std::hash&lt;QString&gt;; _H2 = std::__detail::_Mod_range_hashing; _Hash = std::__detail::_Default_ranged_hash; _Traits = std::__detail::_Hashtable_traits&lt;true, false, true&gt;]’ is implicitly deleted because the default definition would be ill-formed:
185 1822 |     _Hashtable_base() = default;
186      |     ^~~~~~~~~~~~~~~
187/usr/include/c++/9/bits/hashtable_policy.h:1822:5: error: use of deleted function ‘std::__detail::_Hash_code_base&lt;_Key, _Value, _ExtractKey, _H1, _H2, std::__detail::_Default_ranged_hash, true&gt;::_Hash_code_base() [with _Key = QString; _Value = std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;; _ExtractKey = std::__detail::_Select1st; _H1 = std::hash&lt;QString&gt;; _H2 = std::__detail::_Mod_range_hashing]’
188/usr/include/c++/9/bits/hashtable_policy.h:1373:7: note: ‘std::__detail::_Hash_code_base&lt;_Key, _Value, _ExtractKey, _H1, _H2, std::__detail::_Default_ranged_hash, true&gt;::_Hash_code_base() [with _Key = QString; _Value = std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;; _ExtractKey = std::__detail::_Select1st; _H1 = std::hash&lt;QString&gt;; _H2 = std::__detail::_Mod_range_hashing]’ is implicitly deleted because the default definition would be ill-formed:
189 1373 |       _Hash_code_base() = default;
190      |       ^~~~~~~~~~~~~~~
191/usr/include/c++/9/bits/hashtable_policy.h:1373:7: error: use of deleted function ‘std::__detail::_Hashtable_ebo_helper&lt;_Nm, _Tp, true&gt;::_Hashtable_ebo_helper() [with int _Nm = 1; _Tp = std::hash&lt;QString&gt;]’
192/usr/include/c++/9/bits/hashtable_policy.h:1096:7: note: ‘std::__detail::_Hashtable_ebo_helper&lt;_Nm, _Tp, true&gt;::_Hashtable_ebo_helper() [with int _Nm = 1; _Tp = std::hash&lt;QString&gt;]’ is implicitly deleted because the default definition would be ill-formed:
193 1096 |       _Hashtable_ebo_helper() = default;
194      |       ^~~~~~~~~~~~~~~~~~~~~
195/usr/include/c++/9/bits/hashtable_policy.h:1096:7: error: use of deleted function ‘std::hash&lt;QString&gt;::hash()’
196In file included from /usr/include/c++/9/string_view:43,
197                 from /usr/include/c++/9/bits/basic_string.h:48,
198                 from /usr/include/c++/9/string:55,
199                 from /usr/include/c++/9/stdexcept:39,
200                 from /usr/include/c++/9/array:39,
201                 from /usr/include/c++/9/tuple:39,
202                 from /usr/include/c++/9/functional:54,
203                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
204                 from /usr/include/c++/9/algorithm:71,
205                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:142,
206                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qchar.h:43,
207                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:48,
208                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/QString:1,
209                 from /home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h:4,
210                 from /home/rodrigo/devel/unordered_map-qstring/main.cpp:1:
211/usr/include/c++/9/bits/functional_hash.h:101:12: note: ‘std::hash&lt;QString&gt;::hash()’ is implicitly deleted because the default definition would be ill-formed:
212  101 |     struct hash : __hash_enum&lt;_Tp&gt;
213      |            ^~~~
214/usr/include/c++/9/bits/functional_hash.h:101:12: error: no matching function for call to ‘std::__hash_enum&lt;QString, false&gt;::__hash_enum()’
215/usr/include/c++/9/bits/functional_hash.h:82:7: note: candidate: ‘std::__hash_enum&lt;_Tp, &lt;anonymous&gt; &gt;::__hash_enum(std::__hash_enum&lt;_Tp, &lt;anonymous&gt; &gt;&amp;&amp;) [with _Tp = QString; bool &lt;anonymous&gt; = false]’
216   82 |       __hash_enum(__hash_enum&amp;&amp;);
217      |       ^~~~~~~~~~~
218/usr/include/c++/9/bits/functional_hash.h:82:7: note:   candidate expects 1 argument, 0 provided
219/usr/include/c++/9/bits/functional_hash.h:101:12: error: ‘std::__hash_enum&lt;_Tp, &lt;anonymous&gt; &gt;::~__hash_enum() [with _Tp = QString; bool &lt;anonymous&gt; = false]’ is private within this context
220  101 |     struct hash : __hash_enum&lt;_Tp&gt;
221      |            ^~~~
222/usr/include/c++/9/bits/functional_hash.h:83:7: note: declared private here
223   83 |       ~__hash_enum();
224      |       ^
225In file included from /usr/include/c++/9/bits/hashtable.h:35,
226                 from /usr/include/c++/9/unordered_map:46,
227                 from /usr/include/c++/9/functional:61,
228                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
229                 from /usr/include/c++/9/algorithm:71,
230                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:142,
231                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qchar.h:43,
232                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:48,
233                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/QString:1,
234                 from /home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h:4,
235                 from /home/rodrigo/devel/unordered_map-qstring/main.cpp:1:
236/usr/include/c++/9/bits/hashtable_policy.h:1096:7: error: use of deleted function ‘std::hash&lt;QString&gt;::~hash()’
237 1096 |       _Hashtable_ebo_helper() = default;
238      |       ^~~~~~~~~~~~~~~~~~~~~
239In file included from /usr/include/c++/9/string_view:43,
240                 from /usr/include/c++/9/bits/basic_string.h:48,
241                 from /usr/include/c++/9/string:55,
242                 from /usr/include/c++/9/stdexcept:39,
243                 from /usr/include/c++/9/array:39,
244                 from /usr/include/c++/9/tuple:39,
245                 from /usr/include/c++/9/functional:54,
246                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
247                 from /usr/include/c++/9/algorithm:71,
248                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:142,
249                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qchar.h:43,
250                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:48,
251                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/QString:1,
252                 from /home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h:4,
253                 from /home/rodrigo/devel/unordered_map-qstring/main.cpp:1:
254/usr/include/c++/9/bits/functional_hash.h:101:12: note: ‘std::hash&lt;QString&gt;::~hash()’ is implicitly deleted because the default definition would be ill-formed:
255  101 |     struct hash : __hash_enum&lt;_Tp&gt;
256      |            ^~~~
257/usr/include/c++/9/bits/functional_hash.h:101:12: error: ‘std::__hash_enum&lt;_Tp, &lt;anonymous&gt; &gt;::~__hash_enum() [with _Tp = QString; bool &lt;anonymous&gt; = false]’ is private within this context
258/usr/include/c++/9/bits/functional_hash.h:83:7: note: declared private here
259   83 |       ~__hash_enum();
260      |       ^
261In file included from /usr/include/c++/9/bits/hashtable.h:35,
262                 from /usr/include/c++/9/unordered_map:46,
263                 from /usr/include/c++/9/functional:61,
264                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
265                 from /usr/include/c++/9/algorithm:71,
266                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:142,
267                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qchar.h:43,
268                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:48,
269                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/QString:1,
270                 from /home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h:4,
271                 from /home/rodrigo/devel/unordered_map-qstring/main.cpp:1:
272/usr/include/c++/9/bits/hashtable_policy.h:1373:7: error: use of deleted function ‘std::__detail::_Hashtable_ebo_helper&lt;1, std::hash&lt;QString&gt;, true&gt;::~_Hashtable_ebo_helper()’
273 1373 |       _Hash_code_base() = default;
274      |       ^~~~~~~~~~~~~~~
275/usr/include/c++/9/bits/hashtable_policy.h:1093:12: note: ‘std::__detail::_Hashtable_ebo_helper&lt;1, std::hash&lt;QString&gt;, true&gt;::~_Hashtable_ebo_helper()’ is implicitly deleted because the default definition would be ill-formed:
276 1093 |     struct _Hashtable_ebo_helper&lt;_Nm, _Tp, true&gt;
277      |            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
278/usr/include/c++/9/bits/hashtable_policy.h:1093:12: error: use of deleted function ‘std::hash&lt;QString&gt;::~hash()’
279/usr/include/c++/9/bits/hashtable_policy.h:1822:5: error: use of deleted function ‘std::__detail::_Hash_code_base&lt;QString, std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;, std::__detail::_Select1st, std::hash&lt;QString&gt;, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, true&gt;::~_Hash_code_base()’
280 1822 |     _Hashtable_base() = default;
281      |     ^~~~~~~~~~~~~~~
282/usr/include/c++/9/bits/hashtable_policy.h:1346:12: note: ‘std::__detail::_Hash_code_base&lt;QString, std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;, std::__detail::_Select1st, std::hash&lt;QString&gt;, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, true&gt;::~_Hash_code_base()’ is implicitly deleted because the default definition would be ill-formed:
283 1346 |     struct _Hash_code_base&lt;_Key, _Value, _ExtractKey, _H1, _H2,
284      |            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
285 1347 |       _Default_ranged_hash, true&gt;
286      |       ~~~~~~~~~~~~~~~~~~~~~~~~~~~
287/usr/include/c++/9/bits/hashtable_policy.h:1346:12: error: use of deleted function ‘std::__detail::_Hashtable_ebo_helper&lt;1, std::hash&lt;QString&gt;, true&gt;::~_Hashtable_ebo_helper()’
288In file included from /usr/include/c++/9/unordered_map:46,
289                 from /usr/include/c++/9/functional:61,
290                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
291                 from /usr/include/c++/9/algorithm:71,
292                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:142,
293                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qchar.h:43,
294                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:48,
295                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/QString:1,
296                 from /home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h:4,
297                 from /home/rodrigo/devel/unordered_map-qstring/main.cpp:1:
298/usr/include/c++/9/bits/hashtable.h:414:7: error: use of deleted function ‘std::__detail::_Hashtable_base&lt;QString, std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;, std::__detail::_Select1st, std::equal_to&lt;QString&gt;, std::hash&lt;QString&gt;, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Hashtable_traits&lt;true, false, true&gt; &gt;::~_Hashtable_base()’
299  414 |       _Hashtable() = default;
300      |       ^~~~~~~~~~
301In file included from /usr/include/c++/9/bits/hashtable.h:35,
302                 from /usr/include/c++/9/unordered_map:46,
303                 from /usr/include/c++/9/functional:61,
304                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
305                 from /usr/include/c++/9/algorithm:71,
306                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:142,
307                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qchar.h:43,
308                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:48,
309                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/QString:1,
310                 from /home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h:4,
311                 from /home/rodrigo/devel/unordered_map-qstring/main.cpp:1:
312/usr/include/c++/9/bits/hashtable_policy.h:1770:10: note: ‘std::__detail::_Hashtable_base&lt;QString, std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;, std::__detail::_Select1st, std::equal_to&lt;QString&gt;, std::hash&lt;QString&gt;, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Hashtable_traits&lt;true, false, true&gt; &gt;::~_Hashtable_base()’ is implicitly deleted because the default definition would be ill-formed:
313 1770 |   struct _Hashtable_base
314      |          ^~~~~~~~~~~~~~~
315/usr/include/c++/9/bits/hashtable_policy.h:1770:10: error: use of deleted function ‘std::__detail::_Hash_code_base&lt;QString, std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;, std::__detail::_Select1st, std::hash&lt;QString&gt;, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, true&gt;::~_Hash_code_base()’
316In file included from /usr/include/c++/9/unordered_map:46,
317                 from /usr/include/c++/9/functional:61,
318                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
319                 from /usr/include/c++/9/algorithm:71,
320                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:142,
321                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qchar.h:43,
322                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:48,
323                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/QString:1,
324                 from /home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h:4,
325                 from /home/rodrigo/devel/unordered_map-qstring/main.cpp:1:
326/usr/include/c++/9/bits/hashtable.h: In instantiation of ‘std::_Hashtable&lt;_Key, _Value, _Alloc, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy, _Traits&gt;::~_Hashtable() [with _Key = QString; _Value = std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;; _Alloc = std::allocator&lt;std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt; &gt;; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to&lt;QString&gt;; _H1 = std::hash&lt;QString&gt;; _H2 = std::__detail::_Mod_range_hashing; _Hash = std::__detail::_Default_ranged_hash; _RehashPolicy = std::__detail::_Prime_rehash_policy; _Traits = std::__detail::_Hashtable_traits&lt;true, false, true&gt;]’:
327/usr/include/c++/9/bits/unordered_map.h:102:11:   required from here
328/usr/include/c++/9/bits/hashtable.h:1354:5: error: use of deleted function ‘std::__detail::_Hashtable_base&lt;QString, std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;, std::__detail::_Select1st, std::equal_to&lt;QString&gt;, std::hash&lt;QString&gt;, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Hashtable_traits&lt;true, false, true&gt; &gt;::~_Hashtable_base()’
329 1354 |     }
330      |     ^
331make[2]: *** [CMakeFiles/unique_ptr_qstring.dir/build.make:63: CMakeFiles/unique_ptr_qstring.dir/main.cpp.o] Error 1
332make[1]: *** [CMakeFiles/Makefile2:76: CMakeFiles/unique_ptr_qstring.dir/all] Error 2
333make: *** [Makefile:84: all] Error 2
334#ifndef QHASH_QSTRING_H
335#define QHASH_QSTRING_H
336
337#include &lt;QHash&gt;
338#include &lt;QString&gt;
339
340#include &lt;memory&gt;
341
342class QHashQString
343{
344public:
345    QHashQString() {};
346
347    QHash&lt;QString, std::unique_ptr&lt;QString&gt;&gt; container;
348
349    void addItem(QString aKey, std::unique_ptr&lt;QString&gt; aValue);
350
351    void showItem(QString aKey);
352};
353
354#endif // QHASH_QSTRING_H
355#include &quot;qhash_qstring.h&quot;
356
357#include &lt;iostream&gt;
358
359void QHashQString::addItem(QString aKey, std::unique_ptr&lt;QString&gt; aValue)
360{
361    container[aKey] = std::move(aValue);
362}
363
364void QHashQString::showItem(QString aKey)
365{
366    QString *aValue = container[aKey].get();
367    std::cout &lt;&lt; &quot;Item '&quot; &lt;&lt; aKey.toStdString() &lt;&lt; &quot;': '&quot; &lt;&lt; (*aValue).toStdString() &lt;&lt; &quot;'\n&quot;;
368}
369#include &quot;qhash_qstring.h&quot;
370
371#include &lt;memory&gt;
372
373int main(int argc, char *argv[])
374{
375    QHashQString testContainer;
376
377    testContainer.addItem(&quot;key 1&quot;, std::make_unique&lt;QString&gt;(&quot;one value&quot;));
378    testContainer.addItem(&quot;key 2&quot;, std::make_unique&lt;QString&gt;(&quot;two value&quot;));
379    testContainer.addItem(&quot;key 3&quot;, std::make_unique&lt;QString&gt;(&quot;three value&quot;));
380
381    testContainer.showItem(&quot;key 2&quot;);
382    testContainer.showItem(&quot;key 3&quot;);
383    testContainer.showItem(&quot;key 2&quot;);
384
385    return 0;
386}
387
CMakeLists.txt
1#ifndef UNORDERED_MAP_STRING_H
2#define UNORDERED_MAP_STRING_H
3
4#include &lt;memory&gt;
5#include &lt;string&gt;
6#include &lt;unordered_map&gt;
7
8class UnorderedMapString
9{
10public:
11    UnorderedMapString() {};
12
13    std::unordered_map&lt;std::string, std::unique_ptr&lt;std::string&gt;&gt; container;
14
15    void addItem(std::string aKey, std::unique_ptr&lt;std::string&gt; aValue);
16
17    void showItem(std::string aKey);
18};
19
20#endif // UNORDERED_MAP_STRING_H
21#include &quot;unordered_map_string.h&quot;
22
23#include &lt;iostream&gt;
24
25void UnorderedMapString::addItem(std::string aKey, std::unique_ptr&lt;std::string&gt; aValue)
26{
27    container[aKey] = std::move(aValue);
28}
29
30void UnorderedMapString::showItem(std::string aKey)
31{
32    std::string *aValue = container[aKey].get();
33    std::cout &lt;&lt; &quot;Item '&quot; &lt;&lt; aKey &lt;&lt; &quot;': '&quot; &lt;&lt; *aValue &lt;&lt; &quot;'\n&quot;;
34}
35#include &quot;unordered_map_string.h&quot;
36
37#include &lt;memory&gt;
38
39int main(int argc, char *argv[])
40{
41    UnorderedMapString testContainer;
42
43    testContainer.addItem(&quot;key 1&quot;, std::make_unique&lt;std::string&gt;(&quot;one value&quot;));
44    testContainer.addItem(&quot;key 2&quot;, std::make_unique&lt;std::string&gt;(&quot;two value&quot;));
45    testContainer.addItem(&quot;key 3&quot;, std::make_unique&lt;std::string&gt;(&quot;three value&quot;));
46
47    testContainer.showItem(&quot;key 2&quot;);
48    testContainer.showItem(&quot;key 3&quot;);
49    testContainer.showItem(&quot;key 2&quot;);
50
51    return 0;
52}
53cmake_minimum_required(VERSION 3.14)
54
55project(unique_ptr_string LANGUAGES CXX)
56
57set(CMAKE_INCLUDE_CURRENT_DIR ON)
58
59set(CMAKE_CXX_STANDARD 17)
60set(CMAKE_CXX_STANDARD_REQUIRED ON)
61
62add_executable(unique_ptr_string
63  main.cpp
64  unordered_map_string.h unordered_map_string.cpp
65)
66#ifndef UNORDERED_MAP_QSTRING_H
67#define UNORDERED_MAP_QSTRING_H
68
69#include &lt;QString&gt;
70
71#include &lt;memory&gt;
72#include &lt;unordered_map&gt;
73
74class UnorderedMapQString
75{
76public:
77    UnorderedMapQString() {};
78
79    std::unordered_map&lt;QString, std::unique_ptr&lt;QString&gt;&gt; container;
80
81    void addItem(QString aKey, std::unique_ptr&lt;QString&gt; aValue);
82
83    void showItem(QString aKey);
84};
85
86#endif // UNORDERED_MAP_QSTRING_H
87#include &quot;unordered_map_qstring.h&quot;
88
89#include &lt;iostream&gt;
90
91void UnorderedMapQString::addItem(QString aKey, std::unique_ptr&lt;QString&gt; aValue)
92{
93    container[aKey] = std::move(aValue);
94}
95
96void UnorderedMapQString::showItem(QString aKey)
97{
98    QString *aValue = container[aKey].get();
99    std::cout &lt;&lt; &quot;Item '&quot; &lt;&lt; aKey.toStdString() &lt;&lt; &quot;': '&quot; &lt;&lt; (*aValue).toStdString() &lt;&lt; &quot;'\n&quot;;
100}
101#include &quot;unordered_map_qstring.h&quot;
102
103#include &lt;QString&gt;
104
105#include &lt;memory&gt;
106
107int main(int argc, char *argv[])
108{
109    UnorderedMapQString testContainer;
110
111    testContainer.addItem(&quot;key 1&quot;, std::make_unique&lt;QString&gt;(&quot;one value&quot;));
112    testContainer.addItem(&quot;key 2&quot;, std::make_unique&lt;QString&gt;(&quot;two value&quot;));
113    testContainer.addItem(&quot;key 3&quot;, std::make_unique&lt;QString&gt;(&quot;three value&quot;));
114
115    testContainer.showItem(&quot;key 2&quot;);
116    testContainer.showItem(&quot;key 3&quot;);
117    testContainer.showItem(&quot;key 2&quot;);
118
119    return 0;
120}
121cmake_minimum_required(VERSION 3.14)
122
123project(unique_ptr_qstring LANGUAGES CXX)
124
125set(CMAKE_INCLUDE_CURRENT_DIR ON)
126
127set(CMAKE_CXX_STANDARD 17)
128set(CMAKE_CXX_STANDARD_REQUIRED ON)
129
130find_package(QT NAMES Qt6 Qt5 COMPONENTS Core REQUIRED)
131find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core REQUIRED)
132
133add_executable(unique_ptr_qstring
134  main.cpp
135  unordered_map_qstring.h unordered_map_qstring.cpp
136)
137target_link_libraries(unique_ptr_qstring Qt${QT_VERSION_MAJOR}::Core)
138$ make
139[ 33%] Building CXX object CMakeFiles/unique_ptr_qstring.dir/main.cpp.o
140In file included from /home/rodrigo/devel/unordered_map-qstring/main.cpp:1:
141/home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h: In constructor ‘UnorderedMapQString::UnorderedMapQString()’:
142/home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h:12:27: error: use of deleted function ‘std::unordered_map&lt;_Key, _Tp, _Hash, _Pred, _Alloc&gt;::unordered_map() [with _Key = QString; _Tp = std::unique_ptr&lt;QString&gt;; _Hash = std::hash&lt;QString&gt;; _Pred = std::equal_to&lt;QString&gt;; _Alloc = std::allocator&lt;std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt; &gt;]’
143   12 |     UnorderedMapQString() {};
144      |                           ^
145In file included from /usr/include/c++/9/unordered_map:47,
146                 from /usr/include/c++/9/functional:61,
147                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
148                 from /usr/include/c++/9/algorithm:71,
149                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:142,
150                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qchar.h:43,
151                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:48,
152                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/QString:1,
153                 from /home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h:4,
154                 from /home/rodrigo/devel/unordered_map-qstring/main.cpp:1:
155/usr/include/c++/9/bits/unordered_map.h:141:7: note: ‘std::unordered_map&lt;_Key, _Tp, _Hash, _Pred, _Alloc&gt;::unordered_map() [with _Key = QString; _Tp = std::unique_ptr&lt;QString&gt;; _Hash = std::hash&lt;QString&gt;; _Pred = std::equal_to&lt;QString&gt;; _Alloc = std::allocator&lt;std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt; &gt;]’ is implicitly deleted because the default definition would be ill-formed:
156  141 |       unordered_map() = default;
157      |       ^~~~~~~~~~~~~
158/usr/include/c++/9/bits/unordered_map.h:141:7: error: use of deleted function ‘std::_Hashtable&lt;_Key, _Value, _Alloc, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy, _Traits&gt;::_Hashtable() [with _Key = QString; _Value = std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;; _Alloc = std::allocator&lt;std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt; &gt;; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to&lt;QString&gt;; _H1 = std::hash&lt;QString&gt;; _H2 = std::__detail::_Mod_range_hashing; _Hash = std::__detail::_Default_ranged_hash; _RehashPolicy = std::__detail::_Prime_rehash_policy; _Traits = std::__detail::_Hashtable_traits&lt;true, false, true&gt;]’
159In file included from /usr/include/c++/9/unordered_map:46,
160                 from /usr/include/c++/9/functional:61,
161                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
162                 from /usr/include/c++/9/algorithm:71,
163                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:142,
164                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qchar.h:43,
165                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:48,
166                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/QString:1,
167                 from /home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h:4,
168                 from /home/rodrigo/devel/unordered_map-qstring/main.cpp:1:
169/usr/include/c++/9/bits/hashtable.h:414:7: note: ‘std::_Hashtable&lt;_Key, _Value, _Alloc, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy, _Traits&gt;::_Hashtable() [with _Key = QString; _Value = std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;; _Alloc = std::allocator&lt;std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt; &gt;; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to&lt;QString&gt;; _H1 = std::hash&lt;QString&gt;; _H2 = std::__detail::_Mod_range_hashing; _Hash = std::__detail::_Default_ranged_hash; _RehashPolicy = std::__detail::_Prime_rehash_policy; _Traits = std::__detail::_Hashtable_traits&lt;true, false, true&gt; ’ is implicitly deleted because the default definition would be ill-formed:
170  414 |       _Hashtable() = default;
171      |       ^~~~~~~~~~
172/usr/include/c++/9/bits/hashtable.h:414:7: error: use of deleted function ‘std::__detail::_Hashtable_base&lt;_Key, _Value, _ExtractKey, _Equal, _H1, _H2, _Hash, _Traits&gt;::_Hashtable_base() [with _Key = QString; _Value = std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to&lt;QString&gt;; _H1 = std::hash&lt;QString&gt;; _H2 = std::__detail::_Mod_range_hashing; _Hash = std::__detail::_Default_ranged_hash; _Traits = std::__detail::_Hashtable_traits&lt;true, false, true&gt;]’
173In file included from /usr/include/c++/9/bits/hashtable.h:35,
174                 from /usr/include/c++/9/unordered_map:46,
175                 from /usr/include/c++/9/functional:61,
176                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
177                 from /usr/include/c++/9/algorithm:71,
178                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:142,
179                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qchar.h:43,
180                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:48,
181                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/QString:1,
182                 from /home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h:4,
183                 from /home/rodrigo/devel/unordered_map-qstring/main.cpp:1:
184/usr/include/c++/9/bits/hashtable_policy.h:1822:5: note: ‘std::__detail::_Hashtable_base&lt;_Key, _Value, _ExtractKey, _Equal, _H1, _H2, _Hash, _Traits&gt;::_Hashtable_base() [with _Key = QString; _Value = std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to&lt;QString&gt;; _H1 = std::hash&lt;QString&gt;; _H2 = std::__detail::_Mod_range_hashing; _Hash = std::__detail::_Default_ranged_hash; _Traits = std::__detail::_Hashtable_traits&lt;true, false, true&gt;]’ is implicitly deleted because the default definition would be ill-formed:
185 1822 |     _Hashtable_base() = default;
186      |     ^~~~~~~~~~~~~~~
187/usr/include/c++/9/bits/hashtable_policy.h:1822:5: error: use of deleted function ‘std::__detail::_Hash_code_base&lt;_Key, _Value, _ExtractKey, _H1, _H2, std::__detail::_Default_ranged_hash, true&gt;::_Hash_code_base() [with _Key = QString; _Value = std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;; _ExtractKey = std::__detail::_Select1st; _H1 = std::hash&lt;QString&gt;; _H2 = std::__detail::_Mod_range_hashing]’
188/usr/include/c++/9/bits/hashtable_policy.h:1373:7: note: ‘std::__detail::_Hash_code_base&lt;_Key, _Value, _ExtractKey, _H1, _H2, std::__detail::_Default_ranged_hash, true&gt;::_Hash_code_base() [with _Key = QString; _Value = std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;; _ExtractKey = std::__detail::_Select1st; _H1 = std::hash&lt;QString&gt;; _H2 = std::__detail::_Mod_range_hashing]’ is implicitly deleted because the default definition would be ill-formed:
189 1373 |       _Hash_code_base() = default;
190      |       ^~~~~~~~~~~~~~~
191/usr/include/c++/9/bits/hashtable_policy.h:1373:7: error: use of deleted function ‘std::__detail::_Hashtable_ebo_helper&lt;_Nm, _Tp, true&gt;::_Hashtable_ebo_helper() [with int _Nm = 1; _Tp = std::hash&lt;QString&gt;]’
192/usr/include/c++/9/bits/hashtable_policy.h:1096:7: note: ‘std::__detail::_Hashtable_ebo_helper&lt;_Nm, _Tp, true&gt;::_Hashtable_ebo_helper() [with int _Nm = 1; _Tp = std::hash&lt;QString&gt;]’ is implicitly deleted because the default definition would be ill-formed:
193 1096 |       _Hashtable_ebo_helper() = default;
194      |       ^~~~~~~~~~~~~~~~~~~~~
195/usr/include/c++/9/bits/hashtable_policy.h:1096:7: error: use of deleted function ‘std::hash&lt;QString&gt;::hash()’
196In file included from /usr/include/c++/9/string_view:43,
197                 from /usr/include/c++/9/bits/basic_string.h:48,
198                 from /usr/include/c++/9/string:55,
199                 from /usr/include/c++/9/stdexcept:39,
200                 from /usr/include/c++/9/array:39,
201                 from /usr/include/c++/9/tuple:39,
202                 from /usr/include/c++/9/functional:54,
203                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
204                 from /usr/include/c++/9/algorithm:71,
205                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:142,
206                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qchar.h:43,
207                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:48,
208                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/QString:1,
209                 from /home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h:4,
210                 from /home/rodrigo/devel/unordered_map-qstring/main.cpp:1:
211/usr/include/c++/9/bits/functional_hash.h:101:12: note: ‘std::hash&lt;QString&gt;::hash()’ is implicitly deleted because the default definition would be ill-formed:
212  101 |     struct hash : __hash_enum&lt;_Tp&gt;
213      |            ^~~~
214/usr/include/c++/9/bits/functional_hash.h:101:12: error: no matching function for call to ‘std::__hash_enum&lt;QString, false&gt;::__hash_enum()’
215/usr/include/c++/9/bits/functional_hash.h:82:7: note: candidate: ‘std::__hash_enum&lt;_Tp, &lt;anonymous&gt; &gt;::__hash_enum(std::__hash_enum&lt;_Tp, &lt;anonymous&gt; &gt;&amp;&amp;) [with _Tp = QString; bool &lt;anonymous&gt; = false]’
216   82 |       __hash_enum(__hash_enum&amp;&amp;);
217      |       ^~~~~~~~~~~
218/usr/include/c++/9/bits/functional_hash.h:82:7: note:   candidate expects 1 argument, 0 provided
219/usr/include/c++/9/bits/functional_hash.h:101:12: error: ‘std::__hash_enum&lt;_Tp, &lt;anonymous&gt; &gt;::~__hash_enum() [with _Tp = QString; bool &lt;anonymous&gt; = false]’ is private within this context
220  101 |     struct hash : __hash_enum&lt;_Tp&gt;
221      |            ^~~~
222/usr/include/c++/9/bits/functional_hash.h:83:7: note: declared private here
223   83 |       ~__hash_enum();
224      |       ^
225In file included from /usr/include/c++/9/bits/hashtable.h:35,
226                 from /usr/include/c++/9/unordered_map:46,
227                 from /usr/include/c++/9/functional:61,
228                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
229                 from /usr/include/c++/9/algorithm:71,
230                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:142,
231                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qchar.h:43,
232                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:48,
233                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/QString:1,
234                 from /home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h:4,
235                 from /home/rodrigo/devel/unordered_map-qstring/main.cpp:1:
236/usr/include/c++/9/bits/hashtable_policy.h:1096:7: error: use of deleted function ‘std::hash&lt;QString&gt;::~hash()’
237 1096 |       _Hashtable_ebo_helper() = default;
238      |       ^~~~~~~~~~~~~~~~~~~~~
239In file included from /usr/include/c++/9/string_view:43,
240                 from /usr/include/c++/9/bits/basic_string.h:48,
241                 from /usr/include/c++/9/string:55,
242                 from /usr/include/c++/9/stdexcept:39,
243                 from /usr/include/c++/9/array:39,
244                 from /usr/include/c++/9/tuple:39,
245                 from /usr/include/c++/9/functional:54,
246                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
247                 from /usr/include/c++/9/algorithm:71,
248                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:142,
249                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qchar.h:43,
250                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:48,
251                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/QString:1,
252                 from /home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h:4,
253                 from /home/rodrigo/devel/unordered_map-qstring/main.cpp:1:
254/usr/include/c++/9/bits/functional_hash.h:101:12: note: ‘std::hash&lt;QString&gt;::~hash()’ is implicitly deleted because the default definition would be ill-formed:
255  101 |     struct hash : __hash_enum&lt;_Tp&gt;
256      |            ^~~~
257/usr/include/c++/9/bits/functional_hash.h:101:12: error: ‘std::__hash_enum&lt;_Tp, &lt;anonymous&gt; &gt;::~__hash_enum() [with _Tp = QString; bool &lt;anonymous&gt; = false]’ is private within this context
258/usr/include/c++/9/bits/functional_hash.h:83:7: note: declared private here
259   83 |       ~__hash_enum();
260      |       ^
261In file included from /usr/include/c++/9/bits/hashtable.h:35,
262                 from /usr/include/c++/9/unordered_map:46,
263                 from /usr/include/c++/9/functional:61,
264                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
265                 from /usr/include/c++/9/algorithm:71,
266                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:142,
267                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qchar.h:43,
268                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:48,
269                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/QString:1,
270                 from /home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h:4,
271                 from /home/rodrigo/devel/unordered_map-qstring/main.cpp:1:
272/usr/include/c++/9/bits/hashtable_policy.h:1373:7: error: use of deleted function ‘std::__detail::_Hashtable_ebo_helper&lt;1, std::hash&lt;QString&gt;, true&gt;::~_Hashtable_ebo_helper()’
273 1373 |       _Hash_code_base() = default;
274      |       ^~~~~~~~~~~~~~~
275/usr/include/c++/9/bits/hashtable_policy.h:1093:12: note: ‘std::__detail::_Hashtable_ebo_helper&lt;1, std::hash&lt;QString&gt;, true&gt;::~_Hashtable_ebo_helper()’ is implicitly deleted because the default definition would be ill-formed:
276 1093 |     struct _Hashtable_ebo_helper&lt;_Nm, _Tp, true&gt;
277      |            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
278/usr/include/c++/9/bits/hashtable_policy.h:1093:12: error: use of deleted function ‘std::hash&lt;QString&gt;::~hash()’
279/usr/include/c++/9/bits/hashtable_policy.h:1822:5: error: use of deleted function ‘std::__detail::_Hash_code_base&lt;QString, std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;, std::__detail::_Select1st, std::hash&lt;QString&gt;, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, true&gt;::~_Hash_code_base()’
280 1822 |     _Hashtable_base() = default;
281      |     ^~~~~~~~~~~~~~~
282/usr/include/c++/9/bits/hashtable_policy.h:1346:12: note: ‘std::__detail::_Hash_code_base&lt;QString, std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;, std::__detail::_Select1st, std::hash&lt;QString&gt;, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, true&gt;::~_Hash_code_base()’ is implicitly deleted because the default definition would be ill-formed:
283 1346 |     struct _Hash_code_base&lt;_Key, _Value, _ExtractKey, _H1, _H2,
284      |            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
285 1347 |       _Default_ranged_hash, true&gt;
286      |       ~~~~~~~~~~~~~~~~~~~~~~~~~~~
287/usr/include/c++/9/bits/hashtable_policy.h:1346:12: error: use of deleted function ‘std::__detail::_Hashtable_ebo_helper&lt;1, std::hash&lt;QString&gt;, true&gt;::~_Hashtable_ebo_helper()’
288In file included from /usr/include/c++/9/unordered_map:46,
289                 from /usr/include/c++/9/functional:61,
290                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
291                 from /usr/include/c++/9/algorithm:71,
292                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:142,
293                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qchar.h:43,
294                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:48,
295                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/QString:1,
296                 from /home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h:4,
297                 from /home/rodrigo/devel/unordered_map-qstring/main.cpp:1:
298/usr/include/c++/9/bits/hashtable.h:414:7: error: use of deleted function ‘std::__detail::_Hashtable_base&lt;QString, std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;, std::__detail::_Select1st, std::equal_to&lt;QString&gt;, std::hash&lt;QString&gt;, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Hashtable_traits&lt;true, false, true&gt; &gt;::~_Hashtable_base()’
299  414 |       _Hashtable() = default;
300      |       ^~~~~~~~~~
301In file included from /usr/include/c++/9/bits/hashtable.h:35,
302                 from /usr/include/c++/9/unordered_map:46,
303                 from /usr/include/c++/9/functional:61,
304                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
305                 from /usr/include/c++/9/algorithm:71,
306                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:142,
307                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qchar.h:43,
308                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:48,
309                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/QString:1,
310                 from /home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h:4,
311                 from /home/rodrigo/devel/unordered_map-qstring/main.cpp:1:
312/usr/include/c++/9/bits/hashtable_policy.h:1770:10: note: ‘std::__detail::_Hashtable_base&lt;QString, std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;, std::__detail::_Select1st, std::equal_to&lt;QString&gt;, std::hash&lt;QString&gt;, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Hashtable_traits&lt;true, false, true&gt; &gt;::~_Hashtable_base()’ is implicitly deleted because the default definition would be ill-formed:
313 1770 |   struct _Hashtable_base
314      |          ^~~~~~~~~~~~~~~
315/usr/include/c++/9/bits/hashtable_policy.h:1770:10: error: use of deleted function ‘std::__detail::_Hash_code_base&lt;QString, std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;, std::__detail::_Select1st, std::hash&lt;QString&gt;, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, true&gt;::~_Hash_code_base()’
316In file included from /usr/include/c++/9/unordered_map:46,
317                 from /usr/include/c++/9/functional:61,
318                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
319                 from /usr/include/c++/9/algorithm:71,
320                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:142,
321                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qchar.h:43,
322                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:48,
323                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/QString:1,
324                 from /home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h:4,
325                 from /home/rodrigo/devel/unordered_map-qstring/main.cpp:1:
326/usr/include/c++/9/bits/hashtable.h: In instantiation of ‘std::_Hashtable&lt;_Key, _Value, _Alloc, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy, _Traits&gt;::~_Hashtable() [with _Key = QString; _Value = std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;; _Alloc = std::allocator&lt;std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt; &gt;; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to&lt;QString&gt;; _H1 = std::hash&lt;QString&gt;; _H2 = std::__detail::_Mod_range_hashing; _Hash = std::__detail::_Default_ranged_hash; _RehashPolicy = std::__detail::_Prime_rehash_policy; _Traits = std::__detail::_Hashtable_traits&lt;true, false, true&gt;]’:
327/usr/include/c++/9/bits/unordered_map.h:102:11:   required from here
328/usr/include/c++/9/bits/hashtable.h:1354:5: error: use of deleted function ‘std::__detail::_Hashtable_base&lt;QString, std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;, std::__detail::_Select1st, std::equal_to&lt;QString&gt;, std::hash&lt;QString&gt;, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Hashtable_traits&lt;true, false, true&gt; &gt;::~_Hashtable_base()’
329 1354 |     }
330      |     ^
331make[2]: *** [CMakeFiles/unique_ptr_qstring.dir/build.make:63: CMakeFiles/unique_ptr_qstring.dir/main.cpp.o] Error 1
332make[1]: *** [CMakeFiles/Makefile2:76: CMakeFiles/unique_ptr_qstring.dir/all] Error 2
333make: *** [Makefile:84: all] Error 2
334#ifndef QHASH_QSTRING_H
335#define QHASH_QSTRING_H
336
337#include &lt;QHash&gt;
338#include &lt;QString&gt;
339
340#include &lt;memory&gt;
341
342class QHashQString
343{
344public:
345    QHashQString() {};
346
347    QHash&lt;QString, std::unique_ptr&lt;QString&gt;&gt; container;
348
349    void addItem(QString aKey, std::unique_ptr&lt;QString&gt; aValue);
350
351    void showItem(QString aKey);
352};
353
354#endif // QHASH_QSTRING_H
355#include &quot;qhash_qstring.h&quot;
356
357#include &lt;iostream&gt;
358
359void QHashQString::addItem(QString aKey, std::unique_ptr&lt;QString&gt; aValue)
360{
361    container[aKey] = std::move(aValue);
362}
363
364void QHashQString::showItem(QString aKey)
365{
366    QString *aValue = container[aKey].get();
367    std::cout &lt;&lt; &quot;Item '&quot; &lt;&lt; aKey.toStdString() &lt;&lt; &quot;': '&quot; &lt;&lt; (*aValue).toStdString() &lt;&lt; &quot;'\n&quot;;
368}
369#include &quot;qhash_qstring.h&quot;
370
371#include &lt;memory&gt;
372
373int main(int argc, char *argv[])
374{
375    QHashQString testContainer;
376
377    testContainer.addItem(&quot;key 1&quot;, std::make_unique&lt;QString&gt;(&quot;one value&quot;));
378    testContainer.addItem(&quot;key 2&quot;, std::make_unique&lt;QString&gt;(&quot;two value&quot;));
379    testContainer.addItem(&quot;key 3&quot;, std::make_unique&lt;QString&gt;(&quot;three value&quot;));
380
381    testContainer.showItem(&quot;key 2&quot;);
382    testContainer.showItem(&quot;key 3&quot;);
383    testContainer.showItem(&quot;key 2&quot;);
384
385    return 0;
386}
387cmake_minimum_required(VERSION 3.14)
388
389project(qhash_qstring LANGUAGES CXX)
390
391set(CMAKE_INCLUDE_CURRENT_DIR ON)
392
393set(CMAKE_CXX_STANDARD 17)
394set(CMAKE_CXX_STANDARD_REQUIRED ON)
395
396find_package(QT NAMES Qt6 Qt5 COMPONENTS Core REQUIRED)
397find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core REQUIRED)
398
399add_executable(qhash_qstring
400  main.cpp
401  qhash_qstring.h qhash_qstring.cpp
402)
403target_link_libraries(qhash_qstring Qt${QT_VERSION_MAJOR}::Core)
404
Edit 3: compile errors for example 3
1#ifndef UNORDERED_MAP_STRING_H
2#define UNORDERED_MAP_STRING_H
3
4#include &lt;memory&gt;
5#include &lt;string&gt;
6#include &lt;unordered_map&gt;
7
8class UnorderedMapString
9{
10public:
11    UnorderedMapString() {};
12
13    std::unordered_map&lt;std::string, std::unique_ptr&lt;std::string&gt;&gt; container;
14
15    void addItem(std::string aKey, std::unique_ptr&lt;std::string&gt; aValue);
16
17    void showItem(std::string aKey);
18};
19
20#endif // UNORDERED_MAP_STRING_H
21#include &quot;unordered_map_string.h&quot;
22
23#include &lt;iostream&gt;
24
25void UnorderedMapString::addItem(std::string aKey, std::unique_ptr&lt;std::string&gt; aValue)
26{
27    container[aKey] = std::move(aValue);
28}
29
30void UnorderedMapString::showItem(std::string aKey)
31{
32    std::string *aValue = container[aKey].get();
33    std::cout &lt;&lt; &quot;Item '&quot; &lt;&lt; aKey &lt;&lt; &quot;': '&quot; &lt;&lt; *aValue &lt;&lt; &quot;'\n&quot;;
34}
35#include &quot;unordered_map_string.h&quot;
36
37#include &lt;memory&gt;
38
39int main(int argc, char *argv[])
40{
41    UnorderedMapString testContainer;
42
43    testContainer.addItem(&quot;key 1&quot;, std::make_unique&lt;std::string&gt;(&quot;one value&quot;));
44    testContainer.addItem(&quot;key 2&quot;, std::make_unique&lt;std::string&gt;(&quot;two value&quot;));
45    testContainer.addItem(&quot;key 3&quot;, std::make_unique&lt;std::string&gt;(&quot;three value&quot;));
46
47    testContainer.showItem(&quot;key 2&quot;);
48    testContainer.showItem(&quot;key 3&quot;);
49    testContainer.showItem(&quot;key 2&quot;);
50
51    return 0;
52}
53cmake_minimum_required(VERSION 3.14)
54
55project(unique_ptr_string LANGUAGES CXX)
56
57set(CMAKE_INCLUDE_CURRENT_DIR ON)
58
59set(CMAKE_CXX_STANDARD 17)
60set(CMAKE_CXX_STANDARD_REQUIRED ON)
61
62add_executable(unique_ptr_string
63  main.cpp
64  unordered_map_string.h unordered_map_string.cpp
65)
66#ifndef UNORDERED_MAP_QSTRING_H
67#define UNORDERED_MAP_QSTRING_H
68
69#include &lt;QString&gt;
70
71#include &lt;memory&gt;
72#include &lt;unordered_map&gt;
73
74class UnorderedMapQString
75{
76public:
77    UnorderedMapQString() {};
78
79    std::unordered_map&lt;QString, std::unique_ptr&lt;QString&gt;&gt; container;
80
81    void addItem(QString aKey, std::unique_ptr&lt;QString&gt; aValue);
82
83    void showItem(QString aKey);
84};
85
86#endif // UNORDERED_MAP_QSTRING_H
87#include &quot;unordered_map_qstring.h&quot;
88
89#include &lt;iostream&gt;
90
91void UnorderedMapQString::addItem(QString aKey, std::unique_ptr&lt;QString&gt; aValue)
92{
93    container[aKey] = std::move(aValue);
94}
95
96void UnorderedMapQString::showItem(QString aKey)
97{
98    QString *aValue = container[aKey].get();
99    std::cout &lt;&lt; &quot;Item '&quot; &lt;&lt; aKey.toStdString() &lt;&lt; &quot;': '&quot; &lt;&lt; (*aValue).toStdString() &lt;&lt; &quot;'\n&quot;;
100}
101#include &quot;unordered_map_qstring.h&quot;
102
103#include &lt;QString&gt;
104
105#include &lt;memory&gt;
106
107int main(int argc, char *argv[])
108{
109    UnorderedMapQString testContainer;
110
111    testContainer.addItem(&quot;key 1&quot;, std::make_unique&lt;QString&gt;(&quot;one value&quot;));
112    testContainer.addItem(&quot;key 2&quot;, std::make_unique&lt;QString&gt;(&quot;two value&quot;));
113    testContainer.addItem(&quot;key 3&quot;, std::make_unique&lt;QString&gt;(&quot;three value&quot;));
114
115    testContainer.showItem(&quot;key 2&quot;);
116    testContainer.showItem(&quot;key 3&quot;);
117    testContainer.showItem(&quot;key 2&quot;);
118
119    return 0;
120}
121cmake_minimum_required(VERSION 3.14)
122
123project(unique_ptr_qstring LANGUAGES CXX)
124
125set(CMAKE_INCLUDE_CURRENT_DIR ON)
126
127set(CMAKE_CXX_STANDARD 17)
128set(CMAKE_CXX_STANDARD_REQUIRED ON)
129
130find_package(QT NAMES Qt6 Qt5 COMPONENTS Core REQUIRED)
131find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core REQUIRED)
132
133add_executable(unique_ptr_qstring
134  main.cpp
135  unordered_map_qstring.h unordered_map_qstring.cpp
136)
137target_link_libraries(unique_ptr_qstring Qt${QT_VERSION_MAJOR}::Core)
138$ make
139[ 33%] Building CXX object CMakeFiles/unique_ptr_qstring.dir/main.cpp.o
140In file included from /home/rodrigo/devel/unordered_map-qstring/main.cpp:1:
141/home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h: In constructor ‘UnorderedMapQString::UnorderedMapQString()’:
142/home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h:12:27: error: use of deleted function ‘std::unordered_map&lt;_Key, _Tp, _Hash, _Pred, _Alloc&gt;::unordered_map() [with _Key = QString; _Tp = std::unique_ptr&lt;QString&gt;; _Hash = std::hash&lt;QString&gt;; _Pred = std::equal_to&lt;QString&gt;; _Alloc = std::allocator&lt;std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt; &gt;]’
143   12 |     UnorderedMapQString() {};
144      |                           ^
145In file included from /usr/include/c++/9/unordered_map:47,
146                 from /usr/include/c++/9/functional:61,
147                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
148                 from /usr/include/c++/9/algorithm:71,
149                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:142,
150                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qchar.h:43,
151                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:48,
152                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/QString:1,
153                 from /home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h:4,
154                 from /home/rodrigo/devel/unordered_map-qstring/main.cpp:1:
155/usr/include/c++/9/bits/unordered_map.h:141:7: note: ‘std::unordered_map&lt;_Key, _Tp, _Hash, _Pred, _Alloc&gt;::unordered_map() [with _Key = QString; _Tp = std::unique_ptr&lt;QString&gt;; _Hash = std::hash&lt;QString&gt;; _Pred = std::equal_to&lt;QString&gt;; _Alloc = std::allocator&lt;std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt; &gt;]’ is implicitly deleted because the default definition would be ill-formed:
156  141 |       unordered_map() = default;
157      |       ^~~~~~~~~~~~~
158/usr/include/c++/9/bits/unordered_map.h:141:7: error: use of deleted function ‘std::_Hashtable&lt;_Key, _Value, _Alloc, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy, _Traits&gt;::_Hashtable() [with _Key = QString; _Value = std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;; _Alloc = std::allocator&lt;std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt; &gt;; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to&lt;QString&gt;; _H1 = std::hash&lt;QString&gt;; _H2 = std::__detail::_Mod_range_hashing; _Hash = std::__detail::_Default_ranged_hash; _RehashPolicy = std::__detail::_Prime_rehash_policy; _Traits = std::__detail::_Hashtable_traits&lt;true, false, true&gt;]’
159In file included from /usr/include/c++/9/unordered_map:46,
160                 from /usr/include/c++/9/functional:61,
161                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
162                 from /usr/include/c++/9/algorithm:71,
163                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:142,
164                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qchar.h:43,
165                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:48,
166                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/QString:1,
167                 from /home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h:4,
168                 from /home/rodrigo/devel/unordered_map-qstring/main.cpp:1:
169/usr/include/c++/9/bits/hashtable.h:414:7: note: ‘std::_Hashtable&lt;_Key, _Value, _Alloc, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy, _Traits&gt;::_Hashtable() [with _Key = QString; _Value = std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;; _Alloc = std::allocator&lt;std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt; &gt;; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to&lt;QString&gt;; _H1 = std::hash&lt;QString&gt;; _H2 = std::__detail::_Mod_range_hashing; _Hash = std::__detail::_Default_ranged_hash; _RehashPolicy = std::__detail::_Prime_rehash_policy; _Traits = std::__detail::_Hashtable_traits&lt;true, false, true&gt; ’ is implicitly deleted because the default definition would be ill-formed:
170  414 |       _Hashtable() = default;
171      |       ^~~~~~~~~~
172/usr/include/c++/9/bits/hashtable.h:414:7: error: use of deleted function ‘std::__detail::_Hashtable_base&lt;_Key, _Value, _ExtractKey, _Equal, _H1, _H2, _Hash, _Traits&gt;::_Hashtable_base() [with _Key = QString; _Value = std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to&lt;QString&gt;; _H1 = std::hash&lt;QString&gt;; _H2 = std::__detail::_Mod_range_hashing; _Hash = std::__detail::_Default_ranged_hash; _Traits = std::__detail::_Hashtable_traits&lt;true, false, true&gt;]’
173In file included from /usr/include/c++/9/bits/hashtable.h:35,
174                 from /usr/include/c++/9/unordered_map:46,
175                 from /usr/include/c++/9/functional:61,
176                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
177                 from /usr/include/c++/9/algorithm:71,
178                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:142,
179                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qchar.h:43,
180                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:48,
181                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/QString:1,
182                 from /home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h:4,
183                 from /home/rodrigo/devel/unordered_map-qstring/main.cpp:1:
184/usr/include/c++/9/bits/hashtable_policy.h:1822:5: note: ‘std::__detail::_Hashtable_base&lt;_Key, _Value, _ExtractKey, _Equal, _H1, _H2, _Hash, _Traits&gt;::_Hashtable_base() [with _Key = QString; _Value = std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to&lt;QString&gt;; _H1 = std::hash&lt;QString&gt;; _H2 = std::__detail::_Mod_range_hashing; _Hash = std::__detail::_Default_ranged_hash; _Traits = std::__detail::_Hashtable_traits&lt;true, false, true&gt;]’ is implicitly deleted because the default definition would be ill-formed:
185 1822 |     _Hashtable_base() = default;
186      |     ^~~~~~~~~~~~~~~
187/usr/include/c++/9/bits/hashtable_policy.h:1822:5: error: use of deleted function ‘std::__detail::_Hash_code_base&lt;_Key, _Value, _ExtractKey, _H1, _H2, std::__detail::_Default_ranged_hash, true&gt;::_Hash_code_base() [with _Key = QString; _Value = std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;; _ExtractKey = std::__detail::_Select1st; _H1 = std::hash&lt;QString&gt;; _H2 = std::__detail::_Mod_range_hashing]’
188/usr/include/c++/9/bits/hashtable_policy.h:1373:7: note: ‘std::__detail::_Hash_code_base&lt;_Key, _Value, _ExtractKey, _H1, _H2, std::__detail::_Default_ranged_hash, true&gt;::_Hash_code_base() [with _Key = QString; _Value = std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;; _ExtractKey = std::__detail::_Select1st; _H1 = std::hash&lt;QString&gt;; _H2 = std::__detail::_Mod_range_hashing]’ is implicitly deleted because the default definition would be ill-formed:
189 1373 |       _Hash_code_base() = default;
190      |       ^~~~~~~~~~~~~~~
191/usr/include/c++/9/bits/hashtable_policy.h:1373:7: error: use of deleted function ‘std::__detail::_Hashtable_ebo_helper&lt;_Nm, _Tp, true&gt;::_Hashtable_ebo_helper() [with int _Nm = 1; _Tp = std::hash&lt;QString&gt;]’
192/usr/include/c++/9/bits/hashtable_policy.h:1096:7: note: ‘std::__detail::_Hashtable_ebo_helper&lt;_Nm, _Tp, true&gt;::_Hashtable_ebo_helper() [with int _Nm = 1; _Tp = std::hash&lt;QString&gt;]’ is implicitly deleted because the default definition would be ill-formed:
193 1096 |       _Hashtable_ebo_helper() = default;
194      |       ^~~~~~~~~~~~~~~~~~~~~
195/usr/include/c++/9/bits/hashtable_policy.h:1096:7: error: use of deleted function ‘std::hash&lt;QString&gt;::hash()’
196In file included from /usr/include/c++/9/string_view:43,
197                 from /usr/include/c++/9/bits/basic_string.h:48,
198                 from /usr/include/c++/9/string:55,
199                 from /usr/include/c++/9/stdexcept:39,
200                 from /usr/include/c++/9/array:39,
201                 from /usr/include/c++/9/tuple:39,
202                 from /usr/include/c++/9/functional:54,
203                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
204                 from /usr/include/c++/9/algorithm:71,
205                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:142,
206                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qchar.h:43,
207                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:48,
208                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/QString:1,
209                 from /home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h:4,
210                 from /home/rodrigo/devel/unordered_map-qstring/main.cpp:1:
211/usr/include/c++/9/bits/functional_hash.h:101:12: note: ‘std::hash&lt;QString&gt;::hash()’ is implicitly deleted because the default definition would be ill-formed:
212  101 |     struct hash : __hash_enum&lt;_Tp&gt;
213      |            ^~~~
214/usr/include/c++/9/bits/functional_hash.h:101:12: error: no matching function for call to ‘std::__hash_enum&lt;QString, false&gt;::__hash_enum()’
215/usr/include/c++/9/bits/functional_hash.h:82:7: note: candidate: ‘std::__hash_enum&lt;_Tp, &lt;anonymous&gt; &gt;::__hash_enum(std::__hash_enum&lt;_Tp, &lt;anonymous&gt; &gt;&amp;&amp;) [with _Tp = QString; bool &lt;anonymous&gt; = false]’
216   82 |       __hash_enum(__hash_enum&amp;&amp;);
217      |       ^~~~~~~~~~~
218/usr/include/c++/9/bits/functional_hash.h:82:7: note:   candidate expects 1 argument, 0 provided
219/usr/include/c++/9/bits/functional_hash.h:101:12: error: ‘std::__hash_enum&lt;_Tp, &lt;anonymous&gt; &gt;::~__hash_enum() [with _Tp = QString; bool &lt;anonymous&gt; = false]’ is private within this context
220  101 |     struct hash : __hash_enum&lt;_Tp&gt;
221      |            ^~~~
222/usr/include/c++/9/bits/functional_hash.h:83:7: note: declared private here
223   83 |       ~__hash_enum();
224      |       ^
225In file included from /usr/include/c++/9/bits/hashtable.h:35,
226                 from /usr/include/c++/9/unordered_map:46,
227                 from /usr/include/c++/9/functional:61,
228                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
229                 from /usr/include/c++/9/algorithm:71,
230                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:142,
231                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qchar.h:43,
232                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:48,
233                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/QString:1,
234                 from /home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h:4,
235                 from /home/rodrigo/devel/unordered_map-qstring/main.cpp:1:
236/usr/include/c++/9/bits/hashtable_policy.h:1096:7: error: use of deleted function ‘std::hash&lt;QString&gt;::~hash()’
237 1096 |       _Hashtable_ebo_helper() = default;
238      |       ^~~~~~~~~~~~~~~~~~~~~
239In file included from /usr/include/c++/9/string_view:43,
240                 from /usr/include/c++/9/bits/basic_string.h:48,
241                 from /usr/include/c++/9/string:55,
242                 from /usr/include/c++/9/stdexcept:39,
243                 from /usr/include/c++/9/array:39,
244                 from /usr/include/c++/9/tuple:39,
245                 from /usr/include/c++/9/functional:54,
246                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
247                 from /usr/include/c++/9/algorithm:71,
248                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:142,
249                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qchar.h:43,
250                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:48,
251                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/QString:1,
252                 from /home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h:4,
253                 from /home/rodrigo/devel/unordered_map-qstring/main.cpp:1:
254/usr/include/c++/9/bits/functional_hash.h:101:12: note: ‘std::hash&lt;QString&gt;::~hash()’ is implicitly deleted because the default definition would be ill-formed:
255  101 |     struct hash : __hash_enum&lt;_Tp&gt;
256      |            ^~~~
257/usr/include/c++/9/bits/functional_hash.h:101:12: error: ‘std::__hash_enum&lt;_Tp, &lt;anonymous&gt; &gt;::~__hash_enum() [with _Tp = QString; bool &lt;anonymous&gt; = false]’ is private within this context
258/usr/include/c++/9/bits/functional_hash.h:83:7: note: declared private here
259   83 |       ~__hash_enum();
260      |       ^
261In file included from /usr/include/c++/9/bits/hashtable.h:35,
262                 from /usr/include/c++/9/unordered_map:46,
263                 from /usr/include/c++/9/functional:61,
264                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
265                 from /usr/include/c++/9/algorithm:71,
266                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:142,
267                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qchar.h:43,
268                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:48,
269                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/QString:1,
270                 from /home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h:4,
271                 from /home/rodrigo/devel/unordered_map-qstring/main.cpp:1:
272/usr/include/c++/9/bits/hashtable_policy.h:1373:7: error: use of deleted function ‘std::__detail::_Hashtable_ebo_helper&lt;1, std::hash&lt;QString&gt;, true&gt;::~_Hashtable_ebo_helper()’
273 1373 |       _Hash_code_base() = default;
274      |       ^~~~~~~~~~~~~~~
275/usr/include/c++/9/bits/hashtable_policy.h:1093:12: note: ‘std::__detail::_Hashtable_ebo_helper&lt;1, std::hash&lt;QString&gt;, true&gt;::~_Hashtable_ebo_helper()’ is implicitly deleted because the default definition would be ill-formed:
276 1093 |     struct _Hashtable_ebo_helper&lt;_Nm, _Tp, true&gt;
277      |            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
278/usr/include/c++/9/bits/hashtable_policy.h:1093:12: error: use of deleted function ‘std::hash&lt;QString&gt;::~hash()’
279/usr/include/c++/9/bits/hashtable_policy.h:1822:5: error: use of deleted function ‘std::__detail::_Hash_code_base&lt;QString, std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;, std::__detail::_Select1st, std::hash&lt;QString&gt;, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, true&gt;::~_Hash_code_base()’
280 1822 |     _Hashtable_base() = default;
281      |     ^~~~~~~~~~~~~~~
282/usr/include/c++/9/bits/hashtable_policy.h:1346:12: note: ‘std::__detail::_Hash_code_base&lt;QString, std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;, std::__detail::_Select1st, std::hash&lt;QString&gt;, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, true&gt;::~_Hash_code_base()’ is implicitly deleted because the default definition would be ill-formed:
283 1346 |     struct _Hash_code_base&lt;_Key, _Value, _ExtractKey, _H1, _H2,
284      |            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
285 1347 |       _Default_ranged_hash, true&gt;
286      |       ~~~~~~~~~~~~~~~~~~~~~~~~~~~
287/usr/include/c++/9/bits/hashtable_policy.h:1346:12: error: use of deleted function ‘std::__detail::_Hashtable_ebo_helper&lt;1, std::hash&lt;QString&gt;, true&gt;::~_Hashtable_ebo_helper()’
288In file included from /usr/include/c++/9/unordered_map:46,
289                 from /usr/include/c++/9/functional:61,
290                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
291                 from /usr/include/c++/9/algorithm:71,
292                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:142,
293                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qchar.h:43,
294                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:48,
295                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/QString:1,
296                 from /home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h:4,
297                 from /home/rodrigo/devel/unordered_map-qstring/main.cpp:1:
298/usr/include/c++/9/bits/hashtable.h:414:7: error: use of deleted function ‘std::__detail::_Hashtable_base&lt;QString, std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;, std::__detail::_Select1st, std::equal_to&lt;QString&gt;, std::hash&lt;QString&gt;, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Hashtable_traits&lt;true, false, true&gt; &gt;::~_Hashtable_base()’
299  414 |       _Hashtable() = default;
300      |       ^~~~~~~~~~
301In file included from /usr/include/c++/9/bits/hashtable.h:35,
302                 from /usr/include/c++/9/unordered_map:46,
303                 from /usr/include/c++/9/functional:61,
304                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
305                 from /usr/include/c++/9/algorithm:71,
306                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:142,
307                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qchar.h:43,
308                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:48,
309                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/QString:1,
310                 from /home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h:4,
311                 from /home/rodrigo/devel/unordered_map-qstring/main.cpp:1:
312/usr/include/c++/9/bits/hashtable_policy.h:1770:10: note: ‘std::__detail::_Hashtable_base&lt;QString, std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;, std::__detail::_Select1st, std::equal_to&lt;QString&gt;, std::hash&lt;QString&gt;, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Hashtable_traits&lt;true, false, true&gt; &gt;::~_Hashtable_base()’ is implicitly deleted because the default definition would be ill-formed:
313 1770 |   struct _Hashtable_base
314      |          ^~~~~~~~~~~~~~~
315/usr/include/c++/9/bits/hashtable_policy.h:1770:10: error: use of deleted function ‘std::__detail::_Hash_code_base&lt;QString, std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;, std::__detail::_Select1st, std::hash&lt;QString&gt;, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, true&gt;::~_Hash_code_base()’
316In file included from /usr/include/c++/9/unordered_map:46,
317                 from /usr/include/c++/9/functional:61,
318                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
319                 from /usr/include/c++/9/algorithm:71,
320                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:142,
321                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qchar.h:43,
322                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:48,
323                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/QString:1,
324                 from /home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h:4,
325                 from /home/rodrigo/devel/unordered_map-qstring/main.cpp:1:
326/usr/include/c++/9/bits/hashtable.h: In instantiation of ‘std::_Hashtable&lt;_Key, _Value, _Alloc, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy, _Traits&gt;::~_Hashtable() [with _Key = QString; _Value = std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;; _Alloc = std::allocator&lt;std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt; &gt;; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to&lt;QString&gt;; _H1 = std::hash&lt;QString&gt;; _H2 = std::__detail::_Mod_range_hashing; _Hash = std::__detail::_Default_ranged_hash; _RehashPolicy = std::__detail::_Prime_rehash_policy; _Traits = std::__detail::_Hashtable_traits&lt;true, false, true&gt;]’:
327/usr/include/c++/9/bits/unordered_map.h:102:11:   required from here
328/usr/include/c++/9/bits/hashtable.h:1354:5: error: use of deleted function ‘std::__detail::_Hashtable_base&lt;QString, std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;, std::__detail::_Select1st, std::equal_to&lt;QString&gt;, std::hash&lt;QString&gt;, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Hashtable_traits&lt;true, false, true&gt; &gt;::~_Hashtable_base()’
329 1354 |     }
330      |     ^
331make[2]: *** [CMakeFiles/unique_ptr_qstring.dir/build.make:63: CMakeFiles/unique_ptr_qstring.dir/main.cpp.o] Error 1
332make[1]: *** [CMakeFiles/Makefile2:76: CMakeFiles/unique_ptr_qstring.dir/all] Error 2
333make: *** [Makefile:84: all] Error 2
334#ifndef QHASH_QSTRING_H
335#define QHASH_QSTRING_H
336
337#include &lt;QHash&gt;
338#include &lt;QString&gt;
339
340#include &lt;memory&gt;
341
342class QHashQString
343{
344public:
345    QHashQString() {};
346
347    QHash&lt;QString, std::unique_ptr&lt;QString&gt;&gt; container;
348
349    void addItem(QString aKey, std::unique_ptr&lt;QString&gt; aValue);
350
351    void showItem(QString aKey);
352};
353
354#endif // QHASH_QSTRING_H
355#include &quot;qhash_qstring.h&quot;
356
357#include &lt;iostream&gt;
358
359void QHashQString::addItem(QString aKey, std::unique_ptr&lt;QString&gt; aValue)
360{
361    container[aKey] = std::move(aValue);
362}
363
364void QHashQString::showItem(QString aKey)
365{
366    QString *aValue = container[aKey].get();
367    std::cout &lt;&lt; &quot;Item '&quot; &lt;&lt; aKey.toStdString() &lt;&lt; &quot;': '&quot; &lt;&lt; (*aValue).toStdString() &lt;&lt; &quot;'\n&quot;;
368}
369#include &quot;qhash_qstring.h&quot;
370
371#include &lt;memory&gt;
372
373int main(int argc, char *argv[])
374{
375    QHashQString testContainer;
376
377    testContainer.addItem(&quot;key 1&quot;, std::make_unique&lt;QString&gt;(&quot;one value&quot;));
378    testContainer.addItem(&quot;key 2&quot;, std::make_unique&lt;QString&gt;(&quot;two value&quot;));
379    testContainer.addItem(&quot;key 3&quot;, std::make_unique&lt;QString&gt;(&quot;three value&quot;));
380
381    testContainer.showItem(&quot;key 2&quot;);
382    testContainer.showItem(&quot;key 3&quot;);
383    testContainer.showItem(&quot;key 2&quot;);
384
385    return 0;
386}
387cmake_minimum_required(VERSION 3.14)
388
389project(qhash_qstring LANGUAGES CXX)
390
391set(CMAKE_INCLUDE_CURRENT_DIR ON)
392
393set(CMAKE_CXX_STANDARD 17)
394set(CMAKE_CXX_STANDARD_REQUIRED ON)
395
396find_package(QT NAMES Qt6 Qt5 COMPONENTS Core REQUIRED)
397find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core REQUIRED)
398
399add_executable(qhash_qstring
400  main.cpp
401  qhash_qstring.h qhash_qstring.cpp
402)
403target_link_libraries(qhash_qstring Qt${QT_VERSION_MAJOR}::Core)
404$ make
405[ 33%] Building CXX object CMakeFiles/qhash_qstring.dir/qhash_qstring.cpp.o
406In file included from /usr/include/x86_64-linux-gnu/qt5/QtCore/QHash:1,
407                 from /home/rodrigo/devel/qhash-qstring/qhash_qstring.h:4,
408                 from /home/rodrigo/devel/qhash-qstring/qhash_qstring.cpp:1:
409/usr/include/x86_64-linux-gnu/qt5/QtCore/qhash.h: In instantiation of ‘QHashNode&lt;Key, T&gt;::QHashNode(const Key&amp;, const T&amp;, uint, QHashNode&lt;Key, T&gt;*) [with Key = QString; T = std::unique_ptr&lt;QString&gt;; uint = unsigned int]’:
410/usr/include/x86_64-linux-gnu/qt5/QtCore/qhash.h:562:18:   required from ‘QHash&lt;K, V&gt;::Node* QHash&lt;K, V&gt;::createNode(uint, const Key&amp;, const T&amp;, QHash&lt;K, V&gt;::Node**) [with Key = QString; T = std::unique_ptr&lt;QString&gt;; QHash&lt;K, V&gt;::Node = QHashNode&lt;QString, std::unique_ptr&lt;QString&gt; &gt;; uint = unsigned int]’
411/usr/include/x86_64-linux-gnu/qt5/QtCore/qhash.h:762:16:   required from ‘T&amp; QHash&lt;K, V&gt;::operator[](const Key&amp;) [with Key = QString; T = std::unique_ptr&lt;QString&gt;]’
412/home/rodrigo/devel/qhash-qstring/qhash_qstring.cpp:7:19:   required from here
413/usr/include/x86_64-linux-gnu/qt5/QtCore/qhash.h:157:52: error: use of deleted function ‘std::unique_ptr&lt;_Tp, _Dp&gt;::unique_ptr(const std::unique_ptr&lt;_Tp, _Dp&gt;&amp;) [with _Tp = QString; _Dp = std::default_delete&lt;QString&gt;]’
414  157 |         : next(n), h(hash), key(key0), value(value0) {}
415      |                                                    ^
416In file included from /usr/include/c++/9/memory:80,
417                 from /home/rodrigo/devel/qhash-qstring/qhash_qstring.h:7,
418                 from /home/rodrigo/devel/qhash-qstring/qhash_qstring.cpp:1:
419/usr/include/c++/9/bits/unique_ptr.h:414:7: note: declared here
420  414 |       unique_ptr(const unique_ptr&amp;) = delete;
421      |       ^~~~~~~~~~
422make[2]: *** [CMakeFiles/qhash_qstring.dir/build.make:76: CMakeFiles/qhash_qstring.dir/qhash_qstring.cpp.o] Error 1
423make[1]: *** [CMakeFiles/Makefile2:76: CMakeFiles/qhash_qstring.dir/all] Error 2
424make: *** [Makefile:84: all] Error 2
425

ANSWER

Answered 2022-Jan-29 at 20:52

Example 2 does not compile because std::unordered_map requires its key type to be "hashable": by default, it will use the std::hash template. You can make it work by writing a specialisation for QString:

1#ifndef UNORDERED_MAP_STRING_H
2#define UNORDERED_MAP_STRING_H
3
4#include &lt;memory&gt;
5#include &lt;string&gt;
6#include &lt;unordered_map&gt;
7
8class UnorderedMapString
9{
10public:
11    UnorderedMapString() {};
12
13    std::unordered_map&lt;std::string, std::unique_ptr&lt;std::string&gt;&gt; container;
14
15    void addItem(std::string aKey, std::unique_ptr&lt;std::string&gt; aValue);
16
17    void showItem(std::string aKey);
18};
19
20#endif // UNORDERED_MAP_STRING_H
21#include &quot;unordered_map_string.h&quot;
22
23#include &lt;iostream&gt;
24
25void UnorderedMapString::addItem(std::string aKey, std::unique_ptr&lt;std::string&gt; aValue)
26{
27    container[aKey] = std::move(aValue);
28}
29
30void UnorderedMapString::showItem(std::string aKey)
31{
32    std::string *aValue = container[aKey].get();
33    std::cout &lt;&lt; &quot;Item '&quot; &lt;&lt; aKey &lt;&lt; &quot;': '&quot; &lt;&lt; *aValue &lt;&lt; &quot;'\n&quot;;
34}
35#include &quot;unordered_map_string.h&quot;
36
37#include &lt;memory&gt;
38
39int main(int argc, char *argv[])
40{
41    UnorderedMapString testContainer;
42
43    testContainer.addItem(&quot;key 1&quot;, std::make_unique&lt;std::string&gt;(&quot;one value&quot;));
44    testContainer.addItem(&quot;key 2&quot;, std::make_unique&lt;std::string&gt;(&quot;two value&quot;));
45    testContainer.addItem(&quot;key 3&quot;, std::make_unique&lt;std::string&gt;(&quot;three value&quot;));
46
47    testContainer.showItem(&quot;key 2&quot;);
48    testContainer.showItem(&quot;key 3&quot;);
49    testContainer.showItem(&quot;key 2&quot;);
50
51    return 0;
52}
53cmake_minimum_required(VERSION 3.14)
54
55project(unique_ptr_string LANGUAGES CXX)
56
57set(CMAKE_INCLUDE_CURRENT_DIR ON)
58
59set(CMAKE_CXX_STANDARD 17)
60set(CMAKE_CXX_STANDARD_REQUIRED ON)
61
62add_executable(unique_ptr_string
63  main.cpp
64  unordered_map_string.h unordered_map_string.cpp
65)
66#ifndef UNORDERED_MAP_QSTRING_H
67#define UNORDERED_MAP_QSTRING_H
68
69#include &lt;QString&gt;
70
71#include &lt;memory&gt;
72#include &lt;unordered_map&gt;
73
74class UnorderedMapQString
75{
76public:
77    UnorderedMapQString() {};
78
79    std::unordered_map&lt;QString, std::unique_ptr&lt;QString&gt;&gt; container;
80
81    void addItem(QString aKey, std::unique_ptr&lt;QString&gt; aValue);
82
83    void showItem(QString aKey);
84};
85
86#endif // UNORDERED_MAP_QSTRING_H
87#include &quot;unordered_map_qstring.h&quot;
88
89#include &lt;iostream&gt;
90
91void UnorderedMapQString::addItem(QString aKey, std::unique_ptr&lt;QString&gt; aValue)
92{
93    container[aKey] = std::move(aValue);
94}
95
96void UnorderedMapQString::showItem(QString aKey)
97{
98    QString *aValue = container[aKey].get();
99    std::cout &lt;&lt; &quot;Item '&quot; &lt;&lt; aKey.toStdString() &lt;&lt; &quot;': '&quot; &lt;&lt; (*aValue).toStdString() &lt;&lt; &quot;'\n&quot;;
100}
101#include &quot;unordered_map_qstring.h&quot;
102
103#include &lt;QString&gt;
104
105#include &lt;memory&gt;
106
107int main(int argc, char *argv[])
108{
109    UnorderedMapQString testContainer;
110
111    testContainer.addItem(&quot;key 1&quot;, std::make_unique&lt;QString&gt;(&quot;one value&quot;));
112    testContainer.addItem(&quot;key 2&quot;, std::make_unique&lt;QString&gt;(&quot;two value&quot;));
113    testContainer.addItem(&quot;key 3&quot;, std::make_unique&lt;QString&gt;(&quot;three value&quot;));
114
115    testContainer.showItem(&quot;key 2&quot;);
116    testContainer.showItem(&quot;key 3&quot;);
117    testContainer.showItem(&quot;key 2&quot;);
118
119    return 0;
120}
121cmake_minimum_required(VERSION 3.14)
122
123project(unique_ptr_qstring LANGUAGES CXX)
124
125set(CMAKE_INCLUDE_CURRENT_DIR ON)
126
127set(CMAKE_CXX_STANDARD 17)
128set(CMAKE_CXX_STANDARD_REQUIRED ON)
129
130find_package(QT NAMES Qt6 Qt5 COMPONENTS Core REQUIRED)
131find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core REQUIRED)
132
133add_executable(unique_ptr_qstring
134  main.cpp
135  unordered_map_qstring.h unordered_map_qstring.cpp
136)
137target_link_libraries(unique_ptr_qstring Qt${QT_VERSION_MAJOR}::Core)
138$ make
139[ 33%] Building CXX object CMakeFiles/unique_ptr_qstring.dir/main.cpp.o
140In file included from /home/rodrigo/devel/unordered_map-qstring/main.cpp:1:
141/home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h: In constructor ‘UnorderedMapQString::UnorderedMapQString()’:
142/home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h:12:27: error: use of deleted function ‘std::unordered_map&lt;_Key, _Tp, _Hash, _Pred, _Alloc&gt;::unordered_map() [with _Key = QString; _Tp = std::unique_ptr&lt;QString&gt;; _Hash = std::hash&lt;QString&gt;; _Pred = std::equal_to&lt;QString&gt;; _Alloc = std::allocator&lt;std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt; &gt;]’
143   12 |     UnorderedMapQString() {};
144      |                           ^
145In file included from /usr/include/c++/9/unordered_map:47,
146                 from /usr/include/c++/9/functional:61,
147                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
148                 from /usr/include/c++/9/algorithm:71,
149                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:142,
150                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qchar.h:43,
151                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:48,
152                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/QString:1,
153                 from /home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h:4,
154                 from /home/rodrigo/devel/unordered_map-qstring/main.cpp:1:
155/usr/include/c++/9/bits/unordered_map.h:141:7: note: ‘std::unordered_map&lt;_Key, _Tp, _Hash, _Pred, _Alloc&gt;::unordered_map() [with _Key = QString; _Tp = std::unique_ptr&lt;QString&gt;; _Hash = std::hash&lt;QString&gt;; _Pred = std::equal_to&lt;QString&gt;; _Alloc = std::allocator&lt;std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt; &gt;]’ is implicitly deleted because the default definition would be ill-formed:
156  141 |       unordered_map() = default;
157      |       ^~~~~~~~~~~~~
158/usr/include/c++/9/bits/unordered_map.h:141:7: error: use of deleted function ‘std::_Hashtable&lt;_Key, _Value, _Alloc, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy, _Traits&gt;::_Hashtable() [with _Key = QString; _Value = std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;; _Alloc = std::allocator&lt;std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt; &gt;; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to&lt;QString&gt;; _H1 = std::hash&lt;QString&gt;; _H2 = std::__detail::_Mod_range_hashing; _Hash = std::__detail::_Default_ranged_hash; _RehashPolicy = std::__detail::_Prime_rehash_policy; _Traits = std::__detail::_Hashtable_traits&lt;true, false, true&gt;]’
159In file included from /usr/include/c++/9/unordered_map:46,
160                 from /usr/include/c++/9/functional:61,
161                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
162                 from /usr/include/c++/9/algorithm:71,
163                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:142,
164                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qchar.h:43,
165                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:48,
166                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/QString:1,
167                 from /home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h:4,
168                 from /home/rodrigo/devel/unordered_map-qstring/main.cpp:1:
169/usr/include/c++/9/bits/hashtable.h:414:7: note: ‘std::_Hashtable&lt;_Key, _Value, _Alloc, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy, _Traits&gt;::_Hashtable() [with _Key = QString; _Value = std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;; _Alloc = std::allocator&lt;std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt; &gt;; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to&lt;QString&gt;; _H1 = std::hash&lt;QString&gt;; _H2 = std::__detail::_Mod_range_hashing; _Hash = std::__detail::_Default_ranged_hash; _RehashPolicy = std::__detail::_Prime_rehash_policy; _Traits = std::__detail::_Hashtable_traits&lt;true, false, true&gt; ’ is implicitly deleted because the default definition would be ill-formed:
170  414 |       _Hashtable() = default;
171      |       ^~~~~~~~~~
172/usr/include/c++/9/bits/hashtable.h:414:7: error: use of deleted function ‘std::__detail::_Hashtable_base&lt;_Key, _Value, _ExtractKey, _Equal, _H1, _H2, _Hash, _Traits&gt;::_Hashtable_base() [with _Key = QString; _Value = std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to&lt;QString&gt;; _H1 = std::hash&lt;QString&gt;; _H2 = std::__detail::_Mod_range_hashing; _Hash = std::__detail::_Default_ranged_hash; _Traits = std::__detail::_Hashtable_traits&lt;true, false, true&gt;]’
173In file included from /usr/include/c++/9/bits/hashtable.h:35,
174                 from /usr/include/c++/9/unordered_map:46,
175                 from /usr/include/c++/9/functional:61,
176                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
177                 from /usr/include/c++/9/algorithm:71,
178                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:142,
179                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qchar.h:43,
180                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:48,
181                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/QString:1,
182                 from /home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h:4,
183                 from /home/rodrigo/devel/unordered_map-qstring/main.cpp:1:
184/usr/include/c++/9/bits/hashtable_policy.h:1822:5: note: ‘std::__detail::_Hashtable_base&lt;_Key, _Value, _ExtractKey, _Equal, _H1, _H2, _Hash, _Traits&gt;::_Hashtable_base() [with _Key = QString; _Value = std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to&lt;QString&gt;; _H1 = std::hash&lt;QString&gt;; _H2 = std::__detail::_Mod_range_hashing; _Hash = std::__detail::_Default_ranged_hash; _Traits = std::__detail::_Hashtable_traits&lt;true, false, true&gt;]’ is implicitly deleted because the default definition would be ill-formed:
185 1822 |     _Hashtable_base() = default;
186      |     ^~~~~~~~~~~~~~~
187/usr/include/c++/9/bits/hashtable_policy.h:1822:5: error: use of deleted function ‘std::__detail::_Hash_code_base&lt;_Key, _Value, _ExtractKey, _H1, _H2, std::__detail::_Default_ranged_hash, true&gt;::_Hash_code_base() [with _Key = QString; _Value = std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;; _ExtractKey = std::__detail::_Select1st; _H1 = std::hash&lt;QString&gt;; _H2 = std::__detail::_Mod_range_hashing]’
188/usr/include/c++/9/bits/hashtable_policy.h:1373:7: note: ‘std::__detail::_Hash_code_base&lt;_Key, _Value, _ExtractKey, _H1, _H2, std::__detail::_Default_ranged_hash, true&gt;::_Hash_code_base() [with _Key = QString; _Value = std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;; _ExtractKey = std::__detail::_Select1st; _H1 = std::hash&lt;QString&gt;; _H2 = std::__detail::_Mod_range_hashing]’ is implicitly deleted because the default definition would be ill-formed:
189 1373 |       _Hash_code_base() = default;
190      |       ^~~~~~~~~~~~~~~
191/usr/include/c++/9/bits/hashtable_policy.h:1373:7: error: use of deleted function ‘std::__detail::_Hashtable_ebo_helper&lt;_Nm, _Tp, true&gt;::_Hashtable_ebo_helper() [with int _Nm = 1; _Tp = std::hash&lt;QString&gt;]’
192/usr/include/c++/9/bits/hashtable_policy.h:1096:7: note: ‘std::__detail::_Hashtable_ebo_helper&lt;_Nm, _Tp, true&gt;::_Hashtable_ebo_helper() [with int _Nm = 1; _Tp = std::hash&lt;QString&gt;]’ is implicitly deleted because the default definition would be ill-formed:
193 1096 |       _Hashtable_ebo_helper() = default;
194      |       ^~~~~~~~~~~~~~~~~~~~~
195/usr/include/c++/9/bits/hashtable_policy.h:1096:7: error: use of deleted function ‘std::hash&lt;QString&gt;::hash()’
196In file included from /usr/include/c++/9/string_view:43,
197                 from /usr/include/c++/9/bits/basic_string.h:48,
198                 from /usr/include/c++/9/string:55,
199                 from /usr/include/c++/9/stdexcept:39,
200                 from /usr/include/c++/9/array:39,
201                 from /usr/include/c++/9/tuple:39,
202                 from /usr/include/c++/9/functional:54,
203                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
204                 from /usr/include/c++/9/algorithm:71,
205                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:142,
206                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qchar.h:43,
207                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:48,
208                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/QString:1,
209                 from /home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h:4,
210                 from /home/rodrigo/devel/unordered_map-qstring/main.cpp:1:
211/usr/include/c++/9/bits/functional_hash.h:101:12: note: ‘std::hash&lt;QString&gt;::hash()’ is implicitly deleted because the default definition would be ill-formed:
212  101 |     struct hash : __hash_enum&lt;_Tp&gt;
213      |            ^~~~
214/usr/include/c++/9/bits/functional_hash.h:101:12: error: no matching function for call to ‘std::__hash_enum&lt;QString, false&gt;::__hash_enum()’
215/usr/include/c++/9/bits/functional_hash.h:82:7: note: candidate: ‘std::__hash_enum&lt;_Tp, &lt;anonymous&gt; &gt;::__hash_enum(std::__hash_enum&lt;_Tp, &lt;anonymous&gt; &gt;&amp;&amp;) [with _Tp = QString; bool &lt;anonymous&gt; = false]’
216   82 |       __hash_enum(__hash_enum&amp;&amp;);
217      |       ^~~~~~~~~~~
218/usr/include/c++/9/bits/functional_hash.h:82:7: note:   candidate expects 1 argument, 0 provided
219/usr/include/c++/9/bits/functional_hash.h:101:12: error: ‘std::__hash_enum&lt;_Tp, &lt;anonymous&gt; &gt;::~__hash_enum() [with _Tp = QString; bool &lt;anonymous&gt; = false]’ is private within this context
220  101 |     struct hash : __hash_enum&lt;_Tp&gt;
221      |            ^~~~
222/usr/include/c++/9/bits/functional_hash.h:83:7: note: declared private here
223   83 |       ~__hash_enum();
224      |       ^
225In file included from /usr/include/c++/9/bits/hashtable.h:35,
226                 from /usr/include/c++/9/unordered_map:46,
227                 from /usr/include/c++/9/functional:61,
228                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
229                 from /usr/include/c++/9/algorithm:71,
230                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:142,
231                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qchar.h:43,
232                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:48,
233                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/QString:1,
234                 from /home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h:4,
235                 from /home/rodrigo/devel/unordered_map-qstring/main.cpp:1:
236/usr/include/c++/9/bits/hashtable_policy.h:1096:7: error: use of deleted function ‘std::hash&lt;QString&gt;::~hash()’
237 1096 |       _Hashtable_ebo_helper() = default;
238      |       ^~~~~~~~~~~~~~~~~~~~~
239In file included from /usr/include/c++/9/string_view:43,
240                 from /usr/include/c++/9/bits/basic_string.h:48,
241                 from /usr/include/c++/9/string:55,
242                 from /usr/include/c++/9/stdexcept:39,
243                 from /usr/include/c++/9/array:39,
244                 from /usr/include/c++/9/tuple:39,
245                 from /usr/include/c++/9/functional:54,
246                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
247                 from /usr/include/c++/9/algorithm:71,
248                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:142,
249                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qchar.h:43,
250                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:48,
251                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/QString:1,
252                 from /home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h:4,
253                 from /home/rodrigo/devel/unordered_map-qstring/main.cpp:1:
254/usr/include/c++/9/bits/functional_hash.h:101:12: note: ‘std::hash&lt;QString&gt;::~hash()’ is implicitly deleted because the default definition would be ill-formed:
255  101 |     struct hash : __hash_enum&lt;_Tp&gt;
256      |            ^~~~
257/usr/include/c++/9/bits/functional_hash.h:101:12: error: ‘std::__hash_enum&lt;_Tp, &lt;anonymous&gt; &gt;::~__hash_enum() [with _Tp = QString; bool &lt;anonymous&gt; = false]’ is private within this context
258/usr/include/c++/9/bits/functional_hash.h:83:7: note: declared private here
259   83 |       ~__hash_enum();
260      |       ^
261In file included from /usr/include/c++/9/bits/hashtable.h:35,
262                 from /usr/include/c++/9/unordered_map:46,
263                 from /usr/include/c++/9/functional:61,
264                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
265                 from /usr/include/c++/9/algorithm:71,
266                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:142,
267                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qchar.h:43,
268                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:48,
269                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/QString:1,
270                 from /home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h:4,
271                 from /home/rodrigo/devel/unordered_map-qstring/main.cpp:1:
272/usr/include/c++/9/bits/hashtable_policy.h:1373:7: error: use of deleted function ‘std::__detail::_Hashtable_ebo_helper&lt;1, std::hash&lt;QString&gt;, true&gt;::~_Hashtable_ebo_helper()’
273 1373 |       _Hash_code_base() = default;
274      |       ^~~~~~~~~~~~~~~
275/usr/include/c++/9/bits/hashtable_policy.h:1093:12: note: ‘std::__detail::_Hashtable_ebo_helper&lt;1, std::hash&lt;QString&gt;, true&gt;::~_Hashtable_ebo_helper()’ is implicitly deleted because the default definition would be ill-formed:
276 1093 |     struct _Hashtable_ebo_helper&lt;_Nm, _Tp, true&gt;
277      |            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
278/usr/include/c++/9/bits/hashtable_policy.h:1093:12: error: use of deleted function ‘std::hash&lt;QString&gt;::~hash()’
279/usr/include/c++/9/bits/hashtable_policy.h:1822:5: error: use of deleted function ‘std::__detail::_Hash_code_base&lt;QString, std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;, std::__detail::_Select1st, std::hash&lt;QString&gt;, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, true&gt;::~_Hash_code_base()’
280 1822 |     _Hashtable_base() = default;
281      |     ^~~~~~~~~~~~~~~
282/usr/include/c++/9/bits/hashtable_policy.h:1346:12: note: ‘std::__detail::_Hash_code_base&lt;QString, std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;, std::__detail::_Select1st, std::hash&lt;QString&gt;, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, true&gt;::~_Hash_code_base()’ is implicitly deleted because the default definition would be ill-formed:
283 1346 |     struct _Hash_code_base&lt;_Key, _Value, _ExtractKey, _H1, _H2,
284      |            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
285 1347 |       _Default_ranged_hash, true&gt;
286      |       ~~~~~~~~~~~~~~~~~~~~~~~~~~~
287/usr/include/c++/9/bits/hashtable_policy.h:1346:12: error: use of deleted function ‘std::__detail::_Hashtable_ebo_helper&lt;1, std::hash&lt;QString&gt;, true&gt;::~_Hashtable_ebo_helper()’
288In file included from /usr/include/c++/9/unordered_map:46,
289                 from /usr/include/c++/9/functional:61,
290                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
291                 from /usr/include/c++/9/algorithm:71,
292                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:142,
293                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qchar.h:43,
294                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:48,
295                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/QString:1,
296                 from /home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h:4,
297                 from /home/rodrigo/devel/unordered_map-qstring/main.cpp:1:
298/usr/include/c++/9/bits/hashtable.h:414:7: error: use of deleted function ‘std::__detail::_Hashtable_base&lt;QString, std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;, std::__detail::_Select1st, std::equal_to&lt;QString&gt;, std::hash&lt;QString&gt;, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Hashtable_traits&lt;true, false, true&gt; &gt;::~_Hashtable_base()’
299  414 |       _Hashtable() = default;
300      |       ^~~~~~~~~~
301In file included from /usr/include/c++/9/bits/hashtable.h:35,
302                 from /usr/include/c++/9/unordered_map:46,
303                 from /usr/include/c++/9/functional:61,
304                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
305                 from /usr/include/c++/9/algorithm:71,
306                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:142,
307                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qchar.h:43,
308                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:48,
309                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/QString:1,
310                 from /home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h:4,
311                 from /home/rodrigo/devel/unordered_map-qstring/main.cpp:1:
312/usr/include/c++/9/bits/hashtable_policy.h:1770:10: note: ‘std::__detail::_Hashtable_base&lt;QString, std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;, std::__detail::_Select1st, std::equal_to&lt;QString&gt;, std::hash&lt;QString&gt;, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Hashtable_traits&lt;true, false, true&gt; &gt;::~_Hashtable_base()’ is implicitly deleted because the default definition would be ill-formed:
313 1770 |   struct _Hashtable_base
314      |          ^~~~~~~~~~~~~~~
315/usr/include/c++/9/bits/hashtable_policy.h:1770:10: error: use of deleted function ‘std::__detail::_Hash_code_base&lt;QString, std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;, std::__detail::_Select1st, std::hash&lt;QString&gt;, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, true&gt;::~_Hash_code_base()’
316In file included from /usr/include/c++/9/unordered_map:46,
317                 from /usr/include/c++/9/functional:61,
318                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
319                 from /usr/include/c++/9/algorithm:71,
320                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:142,
321                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qchar.h:43,
322                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:48,
323                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/QString:1,
324                 from /home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h:4,
325                 from /home/rodrigo/devel/unordered_map-qstring/main.cpp:1:
326/usr/include/c++/9/bits/hashtable.h: In instantiation of ‘std::_Hashtable&lt;_Key, _Value, _Alloc, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy, _Traits&gt;::~_Hashtable() [with _Key = QString; _Value = std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;; _Alloc = std::allocator&lt;std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt; &gt;; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to&lt;QString&gt;; _H1 = std::hash&lt;QString&gt;; _H2 = std::__detail::_Mod_range_hashing; _Hash = std::__detail::_Default_ranged_hash; _RehashPolicy = std::__detail::_Prime_rehash_policy; _Traits = std::__detail::_Hashtable_traits&lt;true, false, true&gt;]’:
327/usr/include/c++/9/bits/unordered_map.h:102:11:   required from here
328/usr/include/c++/9/bits/hashtable.h:1354:5: error: use of deleted function ‘std::__detail::_Hashtable_base&lt;QString, std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;, std::__detail::_Select1st, std::equal_to&lt;QString&gt;, std::hash&lt;QString&gt;, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Hashtable_traits&lt;true, false, true&gt; &gt;::~_Hashtable_base()’
329 1354 |     }
330      |     ^
331make[2]: *** [CMakeFiles/unique_ptr_qstring.dir/build.make:63: CMakeFiles/unique_ptr_qstring.dir/main.cpp.o] Error 1
332make[1]: *** [CMakeFiles/Makefile2:76: CMakeFiles/unique_ptr_qstring.dir/all] Error 2
333make: *** [Makefile:84: all] Error 2
334#ifndef QHASH_QSTRING_H
335#define QHASH_QSTRING_H
336
337#include &lt;QHash&gt;
338#include &lt;QString&gt;
339
340#include &lt;memory&gt;
341
342class QHashQString
343{
344public:
345    QHashQString() {};
346
347    QHash&lt;QString, std::unique_ptr&lt;QString&gt;&gt; container;
348
349    void addItem(QString aKey, std::unique_ptr&lt;QString&gt; aValue);
350
351    void showItem(QString aKey);
352};
353
354#endif // QHASH_QSTRING_H
355#include &quot;qhash_qstring.h&quot;
356
357#include &lt;iostream&gt;
358
359void QHashQString::addItem(QString aKey, std::unique_ptr&lt;QString&gt; aValue)
360{
361    container[aKey] = std::move(aValue);
362}
363
364void QHashQString::showItem(QString aKey)
365{
366    QString *aValue = container[aKey].get();
367    std::cout &lt;&lt; &quot;Item '&quot; &lt;&lt; aKey.toStdString() &lt;&lt; &quot;': '&quot; &lt;&lt; (*aValue).toStdString() &lt;&lt; &quot;'\n&quot;;
368}
369#include &quot;qhash_qstring.h&quot;
370
371#include &lt;memory&gt;
372
373int main(int argc, char *argv[])
374{
375    QHashQString testContainer;
376
377    testContainer.addItem(&quot;key 1&quot;, std::make_unique&lt;QString&gt;(&quot;one value&quot;));
378    testContainer.addItem(&quot;key 2&quot;, std::make_unique&lt;QString&gt;(&quot;two value&quot;));
379    testContainer.addItem(&quot;key 3&quot;, std::make_unique&lt;QString&gt;(&quot;three value&quot;));
380
381    testContainer.showItem(&quot;key 2&quot;);
382    testContainer.showItem(&quot;key 3&quot;);
383    testContainer.showItem(&quot;key 2&quot;);
384
385    return 0;
386}
387cmake_minimum_required(VERSION 3.14)
388
389project(qhash_qstring LANGUAGES CXX)
390
391set(CMAKE_INCLUDE_CURRENT_DIR ON)
392
393set(CMAKE_CXX_STANDARD 17)
394set(CMAKE_CXX_STANDARD_REQUIRED ON)
395
396find_package(QT NAMES Qt6 Qt5 COMPONENTS Core REQUIRED)
397find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core REQUIRED)
398
399add_executable(qhash_qstring
400  main.cpp
401  qhash_qstring.h qhash_qstring.cpp
402)
403target_link_libraries(qhash_qstring Qt${QT_VERSION_MAJOR}::Core)
404$ make
405[ 33%] Building CXX object CMakeFiles/qhash_qstring.dir/qhash_qstring.cpp.o
406In file included from /usr/include/x86_64-linux-gnu/qt5/QtCore/QHash:1,
407                 from /home/rodrigo/devel/qhash-qstring/qhash_qstring.h:4,
408                 from /home/rodrigo/devel/qhash-qstring/qhash_qstring.cpp:1:
409/usr/include/x86_64-linux-gnu/qt5/QtCore/qhash.h: In instantiation of ‘QHashNode&lt;Key, T&gt;::QHashNode(const Key&amp;, const T&amp;, uint, QHashNode&lt;Key, T&gt;*) [with Key = QString; T = std::unique_ptr&lt;QString&gt;; uint = unsigned int]’:
410/usr/include/x86_64-linux-gnu/qt5/QtCore/qhash.h:562:18:   required from ‘QHash&lt;K, V&gt;::Node* QHash&lt;K, V&gt;::createNode(uint, const Key&amp;, const T&amp;, QHash&lt;K, V&gt;::Node**) [with Key = QString; T = std::unique_ptr&lt;QString&gt;; QHash&lt;K, V&gt;::Node = QHashNode&lt;QString, std::unique_ptr&lt;QString&gt; &gt;; uint = unsigned int]’
411/usr/include/x86_64-linux-gnu/qt5/QtCore/qhash.h:762:16:   required from ‘T&amp; QHash&lt;K, V&gt;::operator[](const Key&amp;) [with Key = QString; T = std::unique_ptr&lt;QString&gt;]’
412/home/rodrigo/devel/qhash-qstring/qhash_qstring.cpp:7:19:   required from here
413/usr/include/x86_64-linux-gnu/qt5/QtCore/qhash.h:157:52: error: use of deleted function ‘std::unique_ptr&lt;_Tp, _Dp&gt;::unique_ptr(const std::unique_ptr&lt;_Tp, _Dp&gt;&amp;) [with _Tp = QString; _Dp = std::default_delete&lt;QString&gt;]’
414  157 |         : next(n), h(hash), key(key0), value(value0) {}
415      |                                                    ^
416In file included from /usr/include/c++/9/memory:80,
417                 from /home/rodrigo/devel/qhash-qstring/qhash_qstring.h:7,
418                 from /home/rodrigo/devel/qhash-qstring/qhash_qstring.cpp:1:
419/usr/include/c++/9/bits/unique_ptr.h:414:7: note: declared here
420  414 |       unique_ptr(const unique_ptr&amp;) = delete;
421      |       ^~~~~~~~~~
422make[2]: *** [CMakeFiles/qhash_qstring.dir/build.make:76: CMakeFiles/qhash_qstring.dir/qhash_qstring.cpp.o] Error 1
423make[1]: *** [CMakeFiles/Makefile2:76: CMakeFiles/qhash_qstring.dir/all] Error 2
424make: *** [Makefile:84: all] Error 2
425#include &lt;functional&gt;     // std::hash
426#include &lt;QHashFunctions&gt; // qHash
427#include &lt;QString&gt;
428
429template&lt;&gt;
430struct std::hash&lt;QString&gt;
431{
432    std::size_t operator()(QString const&amp; s) const noexcept
433    {
434        return qHash(s);
435    }
436};
437

Example 3 does not compile because Qt containers use implicit sharing and only support copy semantics, even when inserting new elements. Therefore the compiler is looking for the copy constructor of std::unique_ptr, which is deleted:

1#ifndef UNORDERED_MAP_STRING_H
2#define UNORDERED_MAP_STRING_H
3
4#include &lt;memory&gt;
5#include &lt;string&gt;
6#include &lt;unordered_map&gt;
7
8class UnorderedMapString
9{
10public:
11    UnorderedMapString() {};
12
13    std::unordered_map&lt;std::string, std::unique_ptr&lt;std::string&gt;&gt; container;
14
15    void addItem(std::string aKey, std::unique_ptr&lt;std::string&gt; aValue);
16
17    void showItem(std::string aKey);
18};
19
20#endif // UNORDERED_MAP_STRING_H
21#include &quot;unordered_map_string.h&quot;
22
23#include &lt;iostream&gt;
24
25void UnorderedMapString::addItem(std::string aKey, std::unique_ptr&lt;std::string&gt; aValue)
26{
27    container[aKey] = std::move(aValue);
28}
29
30void UnorderedMapString::showItem(std::string aKey)
31{
32    std::string *aValue = container[aKey].get();
33    std::cout &lt;&lt; &quot;Item '&quot; &lt;&lt; aKey &lt;&lt; &quot;': '&quot; &lt;&lt; *aValue &lt;&lt; &quot;'\n&quot;;
34}
35#include &quot;unordered_map_string.h&quot;
36
37#include &lt;memory&gt;
38
39int main(int argc, char *argv[])
40{
41    UnorderedMapString testContainer;
42
43    testContainer.addItem(&quot;key 1&quot;, std::make_unique&lt;std::string&gt;(&quot;one value&quot;));
44    testContainer.addItem(&quot;key 2&quot;, std::make_unique&lt;std::string&gt;(&quot;two value&quot;));
45    testContainer.addItem(&quot;key 3&quot;, std::make_unique&lt;std::string&gt;(&quot;three value&quot;));
46
47    testContainer.showItem(&quot;key 2&quot;);
48    testContainer.showItem(&quot;key 3&quot;);
49    testContainer.showItem(&quot;key 2&quot;);
50
51    return 0;
52}
53cmake_minimum_required(VERSION 3.14)
54
55project(unique_ptr_string LANGUAGES CXX)
56
57set(CMAKE_INCLUDE_CURRENT_DIR ON)
58
59set(CMAKE_CXX_STANDARD 17)
60set(CMAKE_CXX_STANDARD_REQUIRED ON)
61
62add_executable(unique_ptr_string
63  main.cpp
64  unordered_map_string.h unordered_map_string.cpp
65)
66#ifndef UNORDERED_MAP_QSTRING_H
67#define UNORDERED_MAP_QSTRING_H
68
69#include &lt;QString&gt;
70
71#include &lt;memory&gt;
72#include &lt;unordered_map&gt;
73
74class UnorderedMapQString
75{
76public:
77    UnorderedMapQString() {};
78
79    std::unordered_map&lt;QString, std::unique_ptr&lt;QString&gt;&gt; container;
80
81    void addItem(QString aKey, std::unique_ptr&lt;QString&gt; aValue);
82
83    void showItem(QString aKey);
84};
85
86#endif // UNORDERED_MAP_QSTRING_H
87#include &quot;unordered_map_qstring.h&quot;
88
89#include &lt;iostream&gt;
90
91void UnorderedMapQString::addItem(QString aKey, std::unique_ptr&lt;QString&gt; aValue)
92{
93    container[aKey] = std::move(aValue);
94}
95
96void UnorderedMapQString::showItem(QString aKey)
97{
98    QString *aValue = container[aKey].get();
99    std::cout &lt;&lt; &quot;Item '&quot; &lt;&lt; aKey.toStdString() &lt;&lt; &quot;': '&quot; &lt;&lt; (*aValue).toStdString() &lt;&lt; &quot;'\n&quot;;
100}
101#include &quot;unordered_map_qstring.h&quot;
102
103#include &lt;QString&gt;
104
105#include &lt;memory&gt;
106
107int main(int argc, char *argv[])
108{
109    UnorderedMapQString testContainer;
110
111    testContainer.addItem(&quot;key 1&quot;, std::make_unique&lt;QString&gt;(&quot;one value&quot;));
112    testContainer.addItem(&quot;key 2&quot;, std::make_unique&lt;QString&gt;(&quot;two value&quot;));
113    testContainer.addItem(&quot;key 3&quot;, std::make_unique&lt;QString&gt;(&quot;three value&quot;));
114
115    testContainer.showItem(&quot;key 2&quot;);
116    testContainer.showItem(&quot;key 3&quot;);
117    testContainer.showItem(&quot;key 2&quot;);
118
119    return 0;
120}
121cmake_minimum_required(VERSION 3.14)
122
123project(unique_ptr_qstring LANGUAGES CXX)
124
125set(CMAKE_INCLUDE_CURRENT_DIR ON)
126
127set(CMAKE_CXX_STANDARD 17)
128set(CMAKE_CXX_STANDARD_REQUIRED ON)
129
130find_package(QT NAMES Qt6 Qt5 COMPONENTS Core REQUIRED)
131find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core REQUIRED)
132
133add_executable(unique_ptr_qstring
134  main.cpp
135  unordered_map_qstring.h unordered_map_qstring.cpp
136)
137target_link_libraries(unique_ptr_qstring Qt${QT_VERSION_MAJOR}::Core)
138$ make
139[ 33%] Building CXX object CMakeFiles/unique_ptr_qstring.dir/main.cpp.o
140In file included from /home/rodrigo/devel/unordered_map-qstring/main.cpp:1:
141/home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h: In constructor ‘UnorderedMapQString::UnorderedMapQString()’:
142/home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h:12:27: error: use of deleted function ‘std::unordered_map&lt;_Key, _Tp, _Hash, _Pred, _Alloc&gt;::unordered_map() [with _Key = QString; _Tp = std::unique_ptr&lt;QString&gt;; _Hash = std::hash&lt;QString&gt;; _Pred = std::equal_to&lt;QString&gt;; _Alloc = std::allocator&lt;std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt; &gt;]’
143   12 |     UnorderedMapQString() {};
144      |                           ^
145In file included from /usr/include/c++/9/unordered_map:47,
146                 from /usr/include/c++/9/functional:61,
147                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
148                 from /usr/include/c++/9/algorithm:71,
149                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:142,
150                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qchar.h:43,
151                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:48,
152                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/QString:1,
153                 from /home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h:4,
154                 from /home/rodrigo/devel/unordered_map-qstring/main.cpp:1:
155/usr/include/c++/9/bits/unordered_map.h:141:7: note: ‘std::unordered_map&lt;_Key, _Tp, _Hash, _Pred, _Alloc&gt;::unordered_map() [with _Key = QString; _Tp = std::unique_ptr&lt;QString&gt;; _Hash = std::hash&lt;QString&gt;; _Pred = std::equal_to&lt;QString&gt;; _Alloc = std::allocator&lt;std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt; &gt;]’ is implicitly deleted because the default definition would be ill-formed:
156  141 |       unordered_map() = default;
157      |       ^~~~~~~~~~~~~
158/usr/include/c++/9/bits/unordered_map.h:141:7: error: use of deleted function ‘std::_Hashtable&lt;_Key, _Value, _Alloc, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy, _Traits&gt;::_Hashtable() [with _Key = QString; _Value = std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;; _Alloc = std::allocator&lt;std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt; &gt;; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to&lt;QString&gt;; _H1 = std::hash&lt;QString&gt;; _H2 = std::__detail::_Mod_range_hashing; _Hash = std::__detail::_Default_ranged_hash; _RehashPolicy = std::__detail::_Prime_rehash_policy; _Traits = std::__detail::_Hashtable_traits&lt;true, false, true&gt;]’
159In file included from /usr/include/c++/9/unordered_map:46,
160                 from /usr/include/c++/9/functional:61,
161                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
162                 from /usr/include/c++/9/algorithm:71,
163                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:142,
164                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qchar.h:43,
165                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:48,
166                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/QString:1,
167                 from /home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h:4,
168                 from /home/rodrigo/devel/unordered_map-qstring/main.cpp:1:
169/usr/include/c++/9/bits/hashtable.h:414:7: note: ‘std::_Hashtable&lt;_Key, _Value, _Alloc, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy, _Traits&gt;::_Hashtable() [with _Key = QString; _Value = std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;; _Alloc = std::allocator&lt;std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt; &gt;; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to&lt;QString&gt;; _H1 = std::hash&lt;QString&gt;; _H2 = std::__detail::_Mod_range_hashing; _Hash = std::__detail::_Default_ranged_hash; _RehashPolicy = std::__detail::_Prime_rehash_policy; _Traits = std::__detail::_Hashtable_traits&lt;true, false, true&gt; ’ is implicitly deleted because the default definition would be ill-formed:
170  414 |       _Hashtable() = default;
171      |       ^~~~~~~~~~
172/usr/include/c++/9/bits/hashtable.h:414:7: error: use of deleted function ‘std::__detail::_Hashtable_base&lt;_Key, _Value, _ExtractKey, _Equal, _H1, _H2, _Hash, _Traits&gt;::_Hashtable_base() [with _Key = QString; _Value = std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to&lt;QString&gt;; _H1 = std::hash&lt;QString&gt;; _H2 = std::__detail::_Mod_range_hashing; _Hash = std::__detail::_Default_ranged_hash; _Traits = std::__detail::_Hashtable_traits&lt;true, false, true&gt;]’
173In file included from /usr/include/c++/9/bits/hashtable.h:35,
174                 from /usr/include/c++/9/unordered_map:46,
175                 from /usr/include/c++/9/functional:61,
176                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
177                 from /usr/include/c++/9/algorithm:71,
178                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:142,
179                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qchar.h:43,
180                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:48,
181                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/QString:1,
182                 from /home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h:4,
183                 from /home/rodrigo/devel/unordered_map-qstring/main.cpp:1:
184/usr/include/c++/9/bits/hashtable_policy.h:1822:5: note: ‘std::__detail::_Hashtable_base&lt;_Key, _Value, _ExtractKey, _Equal, _H1, _H2, _Hash, _Traits&gt;::_Hashtable_base() [with _Key = QString; _Value = std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to&lt;QString&gt;; _H1 = std::hash&lt;QString&gt;; _H2 = std::__detail::_Mod_range_hashing; _Hash = std::__detail::_Default_ranged_hash; _Traits = std::__detail::_Hashtable_traits&lt;true, false, true&gt;]’ is implicitly deleted because the default definition would be ill-formed:
185 1822 |     _Hashtable_base() = default;
186      |     ^~~~~~~~~~~~~~~
187/usr/include/c++/9/bits/hashtable_policy.h:1822:5: error: use of deleted function ‘std::__detail::_Hash_code_base&lt;_Key, _Value, _ExtractKey, _H1, _H2, std::__detail::_Default_ranged_hash, true&gt;::_Hash_code_base() [with _Key = QString; _Value = std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;; _ExtractKey = std::__detail::_Select1st; _H1 = std::hash&lt;QString&gt;; _H2 = std::__detail::_Mod_range_hashing]’
188/usr/include/c++/9/bits/hashtable_policy.h:1373:7: note: ‘std::__detail::_Hash_code_base&lt;_Key, _Value, _ExtractKey, _H1, _H2, std::__detail::_Default_ranged_hash, true&gt;::_Hash_code_base() [with _Key = QString; _Value = std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;; _ExtractKey = std::__detail::_Select1st; _H1 = std::hash&lt;QString&gt;; _H2 = std::__detail::_Mod_range_hashing]’ is implicitly deleted because the default definition would be ill-formed:
189 1373 |       _Hash_code_base() = default;
190      |       ^~~~~~~~~~~~~~~
191/usr/include/c++/9/bits/hashtable_policy.h:1373:7: error: use of deleted function ‘std::__detail::_Hashtable_ebo_helper&lt;_Nm, _Tp, true&gt;::_Hashtable_ebo_helper() [with int _Nm = 1; _Tp = std::hash&lt;QString&gt;]’
192/usr/include/c++/9/bits/hashtable_policy.h:1096:7: note: ‘std::__detail::_Hashtable_ebo_helper&lt;_Nm, _Tp, true&gt;::_Hashtable_ebo_helper() [with int _Nm = 1; _Tp = std::hash&lt;QString&gt;]’ is implicitly deleted because the default definition would be ill-formed:
193 1096 |       _Hashtable_ebo_helper() = default;
194      |       ^~~~~~~~~~~~~~~~~~~~~
195/usr/include/c++/9/bits/hashtable_policy.h:1096:7: error: use of deleted function ‘std::hash&lt;QString&gt;::hash()’
196In file included from /usr/include/c++/9/string_view:43,
197                 from /usr/include/c++/9/bits/basic_string.h:48,
198                 from /usr/include/c++/9/string:55,
199                 from /usr/include/c++/9/stdexcept:39,
200                 from /usr/include/c++/9/array:39,
201                 from /usr/include/c++/9/tuple:39,
202                 from /usr/include/c++/9/functional:54,
203                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
204                 from /usr/include/c++/9/algorithm:71,
205                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:142,
206                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qchar.h:43,
207                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:48,
208                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/QString:1,
209                 from /home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h:4,
210                 from /home/rodrigo/devel/unordered_map-qstring/main.cpp:1:
211/usr/include/c++/9/bits/functional_hash.h:101:12: note: ‘std::hash&lt;QString&gt;::hash()’ is implicitly deleted because the default definition would be ill-formed:
212  101 |     struct hash : __hash_enum&lt;_Tp&gt;
213      |            ^~~~
214/usr/include/c++/9/bits/functional_hash.h:101:12: error: no matching function for call to ‘std::__hash_enum&lt;QString, false&gt;::__hash_enum()’
215/usr/include/c++/9/bits/functional_hash.h:82:7: note: candidate: ‘std::__hash_enum&lt;_Tp, &lt;anonymous&gt; &gt;::__hash_enum(std::__hash_enum&lt;_Tp, &lt;anonymous&gt; &gt;&amp;&amp;) [with _Tp = QString; bool &lt;anonymous&gt; = false]’
216   82 |       __hash_enum(__hash_enum&amp;&amp;);
217      |       ^~~~~~~~~~~
218/usr/include/c++/9/bits/functional_hash.h:82:7: note:   candidate expects 1 argument, 0 provided
219/usr/include/c++/9/bits/functional_hash.h:101:12: error: ‘std::__hash_enum&lt;_Tp, &lt;anonymous&gt; &gt;::~__hash_enum() [with _Tp = QString; bool &lt;anonymous&gt; = false]’ is private within this context
220  101 |     struct hash : __hash_enum&lt;_Tp&gt;
221      |            ^~~~
222/usr/include/c++/9/bits/functional_hash.h:83:7: note: declared private here
223   83 |       ~__hash_enum();
224      |       ^
225In file included from /usr/include/c++/9/bits/hashtable.h:35,
226                 from /usr/include/c++/9/unordered_map:46,
227                 from /usr/include/c++/9/functional:61,
228                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
229                 from /usr/include/c++/9/algorithm:71,
230                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:142,
231                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qchar.h:43,
232                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:48,
233                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/QString:1,
234                 from /home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h:4,
235                 from /home/rodrigo/devel/unordered_map-qstring/main.cpp:1:
236/usr/include/c++/9/bits/hashtable_policy.h:1096:7: error: use of deleted function ‘std::hash&lt;QString&gt;::~hash()’
237 1096 |       _Hashtable_ebo_helper() = default;
238      |       ^~~~~~~~~~~~~~~~~~~~~
239In file included from /usr/include/c++/9/string_view:43,
240                 from /usr/include/c++/9/bits/basic_string.h:48,
241                 from /usr/include/c++/9/string:55,
242                 from /usr/include/c++/9/stdexcept:39,
243                 from /usr/include/c++/9/array:39,
244                 from /usr/include/c++/9/tuple:39,
245                 from /usr/include/c++/9/functional:54,
246                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
247                 from /usr/include/c++/9/algorithm:71,
248                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:142,
249                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qchar.h:43,
250                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:48,
251                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/QString:1,
252                 from /home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h:4,
253                 from /home/rodrigo/devel/unordered_map-qstring/main.cpp:1:
254/usr/include/c++/9/bits/functional_hash.h:101:12: note: ‘std::hash&lt;QString&gt;::~hash()’ is implicitly deleted because the default definition would be ill-formed:
255  101 |     struct hash : __hash_enum&lt;_Tp&gt;
256      |            ^~~~
257/usr/include/c++/9/bits/functional_hash.h:101:12: error: ‘std::__hash_enum&lt;_Tp, &lt;anonymous&gt; &gt;::~__hash_enum() [with _Tp = QString; bool &lt;anonymous&gt; = false]’ is private within this context
258/usr/include/c++/9/bits/functional_hash.h:83:7: note: declared private here
259   83 |       ~__hash_enum();
260      |       ^
261In file included from /usr/include/c++/9/bits/hashtable.h:35,
262                 from /usr/include/c++/9/unordered_map:46,
263                 from /usr/include/c++/9/functional:61,
264                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
265                 from /usr/include/c++/9/algorithm:71,
266                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:142,
267                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qchar.h:43,
268                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:48,
269                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/QString:1,
270                 from /home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h:4,
271                 from /home/rodrigo/devel/unordered_map-qstring/main.cpp:1:
272/usr/include/c++/9/bits/hashtable_policy.h:1373:7: error: use of deleted function ‘std::__detail::_Hashtable_ebo_helper&lt;1, std::hash&lt;QString&gt;, true&gt;::~_Hashtable_ebo_helper()’
273 1373 |       _Hash_code_base() = default;
274      |       ^~~~~~~~~~~~~~~
275/usr/include/c++/9/bits/hashtable_policy.h:1093:12: note: ‘std::__detail::_Hashtable_ebo_helper&lt;1, std::hash&lt;QString&gt;, true&gt;::~_Hashtable_ebo_helper()’ is implicitly deleted because the default definition would be ill-formed:
276 1093 |     struct _Hashtable_ebo_helper&lt;_Nm, _Tp, true&gt;
277      |            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
278/usr/include/c++/9/bits/hashtable_policy.h:1093:12: error: use of deleted function ‘std::hash&lt;QString&gt;::~hash()’
279/usr/include/c++/9/bits/hashtable_policy.h:1822:5: error: use of deleted function ‘std::__detail::_Hash_code_base&lt;QString, std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;, std::__detail::_Select1st, std::hash&lt;QString&gt;, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, true&gt;::~_Hash_code_base()’
280 1822 |     _Hashtable_base() = default;
281      |     ^~~~~~~~~~~~~~~
282/usr/include/c++/9/bits/hashtable_policy.h:1346:12: note: ‘std::__detail::_Hash_code_base&lt;QString, std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;, std::__detail::_Select1st, std::hash&lt;QString&gt;, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, true&gt;::~_Hash_code_base()’ is implicitly deleted because the default definition would be ill-formed:
283 1346 |     struct _Hash_code_base&lt;_Key, _Value, _ExtractKey, _H1, _H2,
284      |            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
285 1347 |       _Default_ranged_hash, true&gt;
286      |       ~~~~~~~~~~~~~~~~~~~~~~~~~~~
287/usr/include/c++/9/bits/hashtable_policy.h:1346:12: error: use of deleted function ‘std::__detail::_Hashtable_ebo_helper&lt;1, std::hash&lt;QString&gt;, true&gt;::~_Hashtable_ebo_helper()’
288In file included from /usr/include/c++/9/unordered_map:46,
289                 from /usr/include/c++/9/functional:61,
290                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
291                 from /usr/include/c++/9/algorithm:71,
292                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:142,
293                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qchar.h:43,
294                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:48,
295                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/QString:1,
296                 from /home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h:4,
297                 from /home/rodrigo/devel/unordered_map-qstring/main.cpp:1:
298/usr/include/c++/9/bits/hashtable.h:414:7: error: use of deleted function ‘std::__detail::_Hashtable_base&lt;QString, std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;, std::__detail::_Select1st, std::equal_to&lt;QString&gt;, std::hash&lt;QString&gt;, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Hashtable_traits&lt;true, false, true&gt; &gt;::~_Hashtable_base()’
299  414 |       _Hashtable() = default;
300      |       ^~~~~~~~~~
301In file included from /usr/include/c++/9/bits/hashtable.h:35,
302                 from /usr/include/c++/9/unordered_map:46,
303                 from /usr/include/c++/9/functional:61,
304                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
305                 from /usr/include/c++/9/algorithm:71,
306                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:142,
307                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qchar.h:43,
308                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:48,
309                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/QString:1,
310                 from /home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h:4,
311                 from /home/rodrigo/devel/unordered_map-qstring/main.cpp:1:
312/usr/include/c++/9/bits/hashtable_policy.h:1770:10: note: ‘std::__detail::_Hashtable_base&lt;QString, std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;, std::__detail::_Select1st, std::equal_to&lt;QString&gt;, std::hash&lt;QString&gt;, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Hashtable_traits&lt;true, false, true&gt; &gt;::~_Hashtable_base()’ is implicitly deleted because the default definition would be ill-formed:
313 1770 |   struct _Hashtable_base
314      |          ^~~~~~~~~~~~~~~
315/usr/include/c++/9/bits/hashtable_policy.h:1770:10: error: use of deleted function ‘std::__detail::_Hash_code_base&lt;QString, std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;, std::__detail::_Select1st, std::hash&lt;QString&gt;, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, true&gt;::~_Hash_code_base()’
316In file included from /usr/include/c++/9/unordered_map:46,
317                 from /usr/include/c++/9/functional:61,
318                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
319                 from /usr/include/c++/9/algorithm:71,
320                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:142,
321                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qchar.h:43,
322                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:48,
323                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/QString:1,
324                 from /home/rodrigo/devel/unordered_map-qstring/unordered_map_qstring.h:4,
325                 from /home/rodrigo/devel/unordered_map-qstring/main.cpp:1:
326/usr/include/c++/9/bits/hashtable.h: In instantiation of ‘std::_Hashtable&lt;_Key, _Value, _Alloc, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy, _Traits&gt;::~_Hashtable() [with _Key = QString; _Value = std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;; _Alloc = std::allocator&lt;std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt; &gt;; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to&lt;QString&gt;; _H1 = std::hash&lt;QString&gt;; _H2 = std::__detail::_Mod_range_hashing; _Hash = std::__detail::_Default_ranged_hash; _RehashPolicy = std::__detail::_Prime_rehash_policy; _Traits = std::__detail::_Hashtable_traits&lt;true, false, true&gt;]’:
327/usr/include/c++/9/bits/unordered_map.h:102:11:   required from here
328/usr/include/c++/9/bits/hashtable.h:1354:5: error: use of deleted function ‘std::__detail::_Hashtable_base&lt;QString, std::pair&lt;const QString, std::unique_ptr&lt;QString&gt; &gt;, std::__detail::_Select1st, std::equal_to&lt;QString&gt;, std::hash&lt;QString&gt;, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Hashtable_traits&lt;true, false, true&gt; &gt;::~_Hashtable_base()’
329 1354 |     }
330      |     ^
331make[2]: *** [CMakeFiles/unique_ptr_qstring.dir/build.make:63: CMakeFiles/unique_ptr_qstring.dir/main.cpp.o] Error 1
332make[1]: *** [CMakeFiles/Makefile2:76: CMakeFiles/unique_ptr_qstring.dir/all] Error 2
333make: *** [Makefile:84: all] Error 2
334#ifndef QHASH_QSTRING_H
335#define QHASH_QSTRING_H
336
337#include &lt;QHash&gt;
338#include &lt;QString&gt;
339
340#include &lt;memory&gt;
341
342class QHashQString
343{
344public:
345    QHashQString() {};
346
347    QHash&lt;QString, std::unique_ptr&lt;QString&gt;&gt; container;
348
349    void addItem(QString aKey, std::unique_ptr&lt;QString&gt; aValue);
350
351    void showItem(QString aKey);
352};
353
354#endif // QHASH_QSTRING_H
355#include &quot;qhash_qstring.h&quot;
356
357#include &lt;iostream&gt;
358
359void QHashQString::addItem(QString aKey, std::unique_ptr&lt;QString&gt; aValue)
360{
361    container[aKey] = std::move(aValue);
362}
363
364void QHashQString::showItem(QString aKey)
365{
366    QString *aValue = container[aKey].get();
367    std::cout &lt;&lt; &quot;Item '&quot; &lt;&lt; aKey.toStdString() &lt;&lt; &quot;': '&quot; &lt;&lt; (*aValue).toStdString() &lt;&lt; &quot;'\n&quot;;
368}
369#include &quot;qhash_qstring.h&quot;
370
371#include &lt;memory&gt;
372
373int main(int argc, char *argv[])
374{
375    QHashQString testContainer;
376
377    testContainer.addItem(&quot;key 1&quot;, std::make_unique&lt;QString&gt;(&quot;one value&quot;));
378    testContainer.addItem(&quot;key 2&quot;, std::make_unique&lt;QString&gt;(&quot;two value&quot;));
379    testContainer.addItem(&quot;key 3&quot;, std::make_unique&lt;QString&gt;(&quot;three value&quot;));
380
381    testContainer.showItem(&quot;key 2&quot;);
382    testContainer.showItem(&quot;key 3&quot;);
383    testContainer.showItem(&quot;key 2&quot;);
384
385    return 0;
386}
387cmake_minimum_required(VERSION 3.14)
388
389project(qhash_qstring LANGUAGES CXX)
390
391set(CMAKE_INCLUDE_CURRENT_DIR ON)
392
393set(CMAKE_CXX_STANDARD 17)
394set(CMAKE_CXX_STANDARD_REQUIRED ON)
395
396find_package(QT NAMES Qt6 Qt5 COMPONENTS Core REQUIRED)
397find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core REQUIRED)
398
399add_executable(qhash_qstring
400  main.cpp
401  qhash_qstring.h qhash_qstring.cpp
402)
403target_link_libraries(qhash_qstring Qt${QT_VERSION_MAJOR}::Core)
404$ make
405[ 33%] Building CXX object CMakeFiles/qhash_qstring.dir/qhash_qstring.cpp.o
406In file included from /usr/include/x86_64-linux-gnu/qt5/QtCore/QHash:1,
407                 from /home/rodrigo/devel/qhash-qstring/qhash_qstring.h:4,
408                 from /home/rodrigo/devel/qhash-qstring/qhash_qstring.cpp:1:
409/usr/include/x86_64-linux-gnu/qt5/QtCore/qhash.h: In instantiation of ‘QHashNode&lt;Key, T&gt;::QHashNode(const Key&amp;, const T&amp;, uint, QHashNode&lt;Key, T&gt;*) [with Key = QString; T = std::unique_ptr&lt;QString&gt;; uint = unsigned int]’:
410/usr/include/x86_64-linux-gnu/qt5/QtCore/qhash.h:562:18:   required from ‘QHash&lt;K, V&gt;::Node* QHash&lt;K, V&gt;::createNode(uint, const Key&amp;, const T&amp;, QHash&lt;K, V&gt;::Node**) [with Key = QString; T = std::unique_ptr&lt;QString&gt;; QHash&lt;K, V&gt;::Node = QHashNode&lt;QString, std::unique_ptr&lt;QString&gt; &gt;; uint = unsigned int]’
411/usr/include/x86_64-linux-gnu/qt5/QtCore/qhash.h:762:16:   required from ‘T&amp; QHash&lt;K, V&gt;::operator[](const Key&amp;) [with Key = QString; T = std::unique_ptr&lt;QString&gt;]’
412/home/rodrigo/devel/qhash-qstring/qhash_qstring.cpp:7:19:   required from here
413/usr/include/x86_64-linux-gnu/qt5/QtCore/qhash.h:157:52: error: use of deleted function ‘std::unique_ptr&lt;_Tp, _Dp&gt;::unique_ptr(const std::unique_ptr&lt;_Tp, _Dp&gt;&amp;) [with _Tp = QString; _Dp = std::default_delete&lt;QString&gt;]’
414  157 |         : next(n), h(hash), key(key0), value(value0) {}
415      |                                                    ^
416In file included from /usr/include/c++/9/memory:80,
417                 from /home/rodrigo/devel/qhash-qstring/qhash_qstring.h:7,
418                 from /home/rodrigo/devel/qhash-qstring/qhash_qstring.cpp:1:
419/usr/include/c++/9/bits/unique_ptr.h:414:7: note: declared here
420  414 |       unique_ptr(const unique_ptr&amp;) = delete;
421      |       ^~~~~~~~~~
422make[2]: *** [CMakeFiles/qhash_qstring.dir/build.make:76: CMakeFiles/qhash_qstring.dir/qhash_qstring.cpp.o] Error 1
423make[1]: *** [CMakeFiles/Makefile2:76: CMakeFiles/qhash_qstring.dir/all] Error 2
424make: *** [Makefile:84: all] Error 2
425#include &lt;functional&gt;     // std::hash
426#include &lt;QHashFunctions&gt; // qHash
427#include &lt;QString&gt;
428
429template&lt;&gt;
430struct std::hash&lt;QString&gt;
431{
432    std::size_t operator()(QString const&amp; s) const noexcept
433    {
434        return qHash(s);
435    }
436};
437unique_ptr(const unique_ptr&amp;) = delete;
438

This example cannot be made to work, it's a fundamental design difference between Qt and standard library containers.

Source https://stackoverflow.com/questions/70904952

Community Discussions contain sources that include Stack Exchange Network

Tutorials and Learning Resources in Qt5

Tutorials and Learning Resources are not available at this moment for Qt5

Share this Page

share link

Get latest updates on Qt5