Unsolved Sorting a tree view. Qt5 vs Qt4 issue.
-
Noted, but doing that breaks the project using Qt4.
-
Hi,
In what way ? Qt 4 should also support C++11
-
Qt4 does support C++11. To clarify, it's that appending "CONFIG += c++11" doesn't work when I try it with Qt4, but appending "QMAKE_CXXFLAGS += -std=c++11" does.
-
Can you give more details about what "doesn't work" means in that case ?
-
- 99.999% convinced you have a race condition on
halt_m
(should bestd::atomic_bool
to work correctly). - I still don't understand what the problem is. What is happening in Qt5 that is not happening in Qt4?
- 99.999% convinced you have a race condition on
-
Yes, std::atomic_bool would have been a better choice for halt_m. I'll be sure to utilize it in the future, but that's not the issue here.
I see now that I did a poor job of stating my actual problem, so here it is.
I'm concerned with whether or not the QTreeView is being sorted.
When build using Qt5, the tree gets sorted. Everything is fine.
When build in Qt4, the tree doesn't get sorted. I don't know why. -
Sorry, missed your response SGaist.
By "doesn't work" I mean that if I append "CONFIG += c++11" instead of "QMAKE_CXXFLAGS += -std=c++11" to the project file, then (in Qt4) it will fail to build (complaining that insert C++11 feature here requires the -std=c++11 flag) as though I hadn't appended anything at all.
In addition, I didn't have to append anything until I tried to build it in Qt4. Building in Qt5 (which is what I started in) required no additional modification to the project file.
-
Might be a silly question but did you re-run qmake after adding
CONFIG += c++11
? -
@SGaist < Hey, I did this right!
Yes. Just to be absolutely sure, I closed Qt Creator, I wiped out the build folder and all *.pro.* (*.pro.user etc...) files, and changedQMAKE_CXXFLAGS += -std=c++11
toCONFIG += c++11
at the end of the project file with some text editor outside of Qt Creator.The following is the result after freshly loading qt_proxy_model_test.pro into Qt Creator and trying to build.
This is the actual compile output.
15:46:53: Running steps for project qt_proxy_model_test... 15:46:53: Starting: "/usr/lib64/qt4/bin/qmake" /home/system/git/qt_proxy_model_test/qt_proxy_model_test.pro -r -spec linux-g++ CONFIG+=debug 15:46:53: The process "/usr/lib64/qt4/bin/qmake" exited normally. 15:46:53: Starting: "/usr/bin/make" /usr/lib64/qt4/bin/uic ../qt_proxy_model_test/mainwindow.ui -o ui_mainwindow.h g++ -c -pipe -g -Wall -W -D_REENTRANT -DQT_DEPRECATED_WARNINGS -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++ -I../qt_proxy_model_test -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -I. -I../qt_proxy_model_test -I. -o main.o ../qt_proxy_model_test/main.cpp g++ -c -pipe -g -Wall -W -D_REENTRANT -DQT_DEPRECATED_WARNINGS -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++ -I../qt_proxy_model_test -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -I. -I../qt_proxy_model_test -I. -o mainwindow.o ../qt_proxy_model_test/mainwindow.cpp In file included from /usr/lib/gcc/x86_64-pc-linux-gnu/4.8.5/include/g++-v4/thread:35:0, from ../qt_proxy_model_test/mainwindow.cpp:7: /usr/lib/gcc/x86_64-pc-linux-gnu/4.8.5/include/g++-v4/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options. #error This file requires compiler and library support for the \ ^ ../qt_proxy_model_test/mainwindow.cpp: In function ‘void status_update_thread(MainWindow*, bool*)’: ../qt_proxy_model_test/mainwindow.cpp:15:8: error: ‘std::this_thread’ has not been declared std::this_thread::sleep_for(std::chrono::milliseconds(2000)); ^ ../qt_proxy_model_test/mainwindow.cpp:15:36: error: ‘std::chrono’ has not been declared std::this_thread::sleep_for(std::chrono::milliseconds(2000)); ^ ../qt_proxy_model_test/mainwindow.cpp: In constructor ‘MainWindow::MainWindow(QWidget*)’: ../qt_proxy_model_test/mainwindow.cpp:26:59: error: invalid use of incomplete type ‘class std::thread’ t1_m = new std::thread(status_update_thread, this, halt_m); ^ In file included from ../qt_proxy_model_test/mainwindow.cpp:1:0: ../qt_proxy_model_test/mainwindow.hpp:9:7: error: forward declaration of ‘class std::thread’ class thread; ^ ../qt_proxy_model_test/mainwindow.cpp:33:47: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11 [enabled by default] model_m.setHorizontalHeaderLabels(QStringList({"Tree Info"})); ^ ../qt_proxy_model_test/mainwindow.cpp:33:61: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11 [enabled by default] model_m.setHorizontalHeaderLabels(QStringList({"Tree Info"})); ^ ../qt_proxy_model_test/mainwindow.cpp:33:61: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11 [enabled by default] ../qt_proxy_model_test/mainwindow.cpp:33:61: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11 [enabled by default] ../qt_proxy_model_test/mainwindow.cpp:33:61: error: call of overloaded ‘QStringList(<brace-enclosed initializer list>)’ is ambiguous ../qt_proxy_model_test/mainwindow.cpp:33:61: note: candidates are: In file included from /usr/include/qt4/QtGui/qcolor.h:47:0, from /usr/include/qt4/QtGui/qpalette.h:46, from /usr/include/qt4/QtGui/qwidget.h:50, from /usr/include/qt4/QtGui/qmainwindow.h:45, from /usr/include/qt4/QtGui/QMainWindow:1, from ../qt_proxy_model_test/mainwindow.hpp:4, from ../qt_proxy_model_test/mainwindow.cpp:1: /usr/include/qt4/QtCore/qstringlist.h:71:12: note: QStringList::QStringList(const QStringList&) inline QStringList(const QStringList &l) : QList<QString>(l) { } ^ /usr/include/qt4/QtCore/qstringlist.h:70:21: note: QStringList::QStringList(const QString&) inline explicit QStringList(const QString &i) { append(i); } ^ ../qt_proxy_model_test/mainwindow.cpp: In destructor ‘virtual MainWindow::~MainWindow()’: ../qt_proxy_model_test/mainwindow.cpp:40:6: error: invalid use of incomplete type ‘class std::thread’ t1_m->join(); ^ In file included from ../qt_proxy_model_test/mainwindow.cpp:1:0: ../qt_proxy_model_test/mainwindow.hpp:9:7: error: forward declaration of ‘class std::thread’ class thread; ^ make: *** [Makefile:233: mainwindow.o] Error 1 15:46:54: The process "/usr/bin/make" exited with code 2. Error while building/deploying project qt_proxy_model_test (kit: Desktop) When executing step "Make" 15:46:54: Elapsed time: 00:01.
And this is the project file: qt_proxy_model_test.pro
#------------------------------------------------- # # Project created by QtCreator 2017-03-06T11:09:29 # #------------------------------------------------- QT += core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = qt_proxy_model_test TEMPLATE = app # The following define makes your compiler emit warnings if you use # any feature of Qt which as been marked as deprecated (the exact warnings # depend on your compiler). Please consult the documentation of the # deprecated API in order to know how to port your code away from it. DEFINES += QT_DEPRECATED_WARNINGS # You can also make your code fail to compile if you use deprecated APIs. # In order to do so, uncomment the following line. # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 SOURCES += main.cpp\ mainwindow.cpp HEADERS += mainwindow.hpp \ priv.hpp FORMS += mainwindow.ui CONFIG += c++11
-
Ok, I just double checked to be sure.
CONFIG += c++11
seems to be Qt 5 only, so you can do something like:greaterThan(QT_MAJOR_VERSION, 4) { CONFIG += c++11 } else { QMAKE_CXXFLAGS += -std=c++11 }