Tutorial example suddenly stopped compiling
-
Hi. I´m testing out qt creator.
I followed this tutorial for a bit:
https://wiki.qt.io/Qt_for_Beginners
and it worked fine.
Then I started making my own project with some frames and buttons, and it also worked.But then suddenly when making some change (it might have been when I added unique_ptr for the first time) it stopped compiling.
I removed code but as long as I included "QApplication" I got the same error.Then I tried following the tutorial again with a new project, but I still get the same error even with the minimal code example in the tutorial.
#include <QApplication> int main(int argc, char **argv) { QApplication app (argc, argv); return app.exec(); }
TEMPLATE = app TARGET = name_of_the_app QT = core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets SOURCES += \ main.cpp
(the tutorial creates a "empty qt project", but that option does not exist for me, so I created a "empty qmake project", I assume it´s just a name change).
I get the error on the #include line, and the errors is
"named return values are no longer suppored" unique_ptr.h:1070
"'__num' was not declared in this scope" unique_ptr.h:1085I dont even use unique_ptr in the project.
I feel like I broke something in the environment just by including unique_ptr once, but there might have been something else that cased it.
Annyone knows why this happend and how to solve it?
-
Try explicitly setting he c++ standard:
qmake: in pro file
CONFIG += c++17
in cmake
set(CMAKE_CXX_STANDARD 17) # Use C++17 set(CMAKE_CXX_STANDARD_REQUIRED ON) # Enforce it (don’t silently downgrade) set(CMAKE_CXX_EXTENSIONS OFF) # Avoid compiler-specific extensions (use pure C++)
-
It´s either qmake or cmake right? I´m not supposed to do both those things? Because I dont know how to use cmake.
I added the line in the project.
TEMPLATE = app TARGET = name_of_the_app QT = core gui CONFIG += c++17 greaterThan(QT_MAJOR_VERSION, 4): QT += widgets SOURCES += \ main.cpp
Tried putting it on a few different lines. Each time I clean, run qmake, rebuild.
I also tried deleting the files in the build\Desktop_Qt_6_9_0_MinGW_64_bit-Debug folder.
Still gets the same errors.I now also get this error on the include line (perhaps I did before to)
C:\Github\EconomyViewer2\EcoTest\main.cpp:1: error: In included file: expected function body after function declarator -
I have also tried to create "non-qt project"->"Plain c++ application" and just add the line
#include <memory>
in the beginning of main.cpp and it gives me the same errors.
Two of the three lines you tipped to add in the cmake file was already there. I added the third one to, but still the same errors.These are the lines in unique_ptr.h it complains about:
/** Create an object owned by a `unique_ptr`. * @tparam _Tp A non-array object type. * @param __args Constructor arguments for the new object. * @returns A `unique_ptr<_Tp>` that owns the new object. * @since C++14 * @relates unique_ptr */ template<typename _Tp, typename... _Args> _GLIBCXX23_CONSTEXPR inline __detail::__unique_ptr_t<_Tp> make_unique(_Args&&... __args) return unique_ptr<_Tp>(new _Tp(std::forward<_Args>(__args)...)); } /** Create an array owned by a `unique_ptr`. * @tparam _Tp An array type of unknown bound, such as `U[]`. * @param __num The number of elements of type `U` in the new array. * @returns A `unique_ptr<U[]>` that owns the new array. * @since C++14 * @relates unique_ptr * * The array elements are value-initialized. */ template<typename _Tp> _GLIBCXX23_CONSTEXPR inline __detail::__unique_ptr_array_t<_Tp> make_unique(size_t __num) { return unique_ptr<_Tp>(new remove_extent_t<_Tp>[__num]()); }
"named return values are no longer supported" at the first return statement,
and "__num was not declared in this scope" on the second last line.Something with the version of my memory.h file and c++ version I compile for perhaps?
Is the memory.h part of the qt creator installation, or is it on my system? (I have other IDEs, codeblocks and visual studio).
I dont know where to look, and I dont find annything on google.
Nobody else had this problem? -
I reinstalled qt creator, and then i could compile (this also upgraded version from 6.9.0 to 6.9.1).
Dont know what happend.
I found one more clue. If i made a cmake project and targeted c++11 i could compile, all other combinations of cmake/qmake c++11/14/17 did not work.