为什么我不能正常使用qt在linux中编程

时间:2017-05-21 03:50:48

标签: c++ linux qt

我是QT的新手,所以我想先写一个“Hello World”来学习QT。

1.首先,我在我的电脑上安装了QT5。(Archlinux)。

sudo pacman -S qt5-base qt5

然后,我安装了qt-creator。

sudo pacman -S qtcreator

并且,我使用QT创建者创建一个新项目(我选择Qt widgets Application)。

IDE会自动生成一些代码。我不会在源文件中添加任何代码。

.pro:

#-------------------------------------------------
#
# Project created by QtCreator 2017-05-21T14:48:56
#
#-------------------------------------------------

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = untitled
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.h

FORMS    += mainwindow.ui

我认为在构建和运行时它应该生成一个空白窗口。

然而,当我尝试构建并运行时。有很多问题。

图片

我不知道为什么会这样。

然后我尝试使用官方示例。我遵循官方教程Building and Running an Example。然后,当我尝试构建和运行时会发生同样的问题。

2.Wyzard说我应该使用std=c++11来编译程序。

所以,我创建了一个main.cpp文件。

main.cpp:

 #include <QApplication>
 #include <QPushButton>

 int main(int argc, char *argv[])
 {
    QApplication app(argc, argv);

    QPushButton hello("Hello world!");
    hello.resize(100, 30);

    hello.show();
    return app.exec();
 }

然后,我使用qmake生成一个makefile。

$qmake -project

$qmake 

并且,我将-std=c++11添加到编译标志。

make

output:

g++ -c -pipe -O2 -march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong -Wall -W -D_REENTRANT -fPIC -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -std=c++11 -I. -I. -isystem /usr/include/qt -isystem /usr/include/qt/QtGui -isystem /usr/include/qt/QtCore -I. -isystem /usr/include/libdrm -I/usr/lib/qt/mkspecs/linux-g++ -I/usr/include/qt/QtWidgets/ -o hello.o hello.cpp

In file included from /usr/include/qt/QtCore/qbasicatomic.h:53:0,
                 from /usr/include/qt/QtCore/qatomic.h:46,
                 from /usr/include/qt/QtCore/qglobal.h:1129,
                 from /usr/include/qt/QtGui/qtguiglobal.h:43,
                 from /usr/include/qt/QtWidgets/qtwidgetsglobal.h:43,
                 from /usr/include/qt/QtWidgets/qapplication.h:43,
                 from /usr/include/qt/QtWidgets/QApplication:1,
                 from hello.cpp:1:
/usr/include/qt/QtCore/qatomic_cxx11.h:222:18: error: ‘atomic’ in namespace ‘std’ does not name a template type
     typedef std::atomic<X> Type;
                  ^~~~~~
/usr/include/qt/QtCore/qatomic_cxx11.h:225:23: error: ‘atomic’ in namespace ‘std’ does not name a template type
     T load(const std::atomic<T> &_q_value) Q_DECL_NOTHROW
                       ^~~~~~
/usr/include/qt/QtCore/qatomic_cxx11.h:225:29: error: expected ‘,’ or ‘...’ before ‘<’ token
     T load(const std::atomic<T> &_q_value) Q_DECL_NOTHROW
                             ^
/usr/include/qt/QtCore/qatomic_cxx11.h:231:32: error: ‘atomic’ in namespace ‘std’ does not name a template type
     T load(const volatile std::atomic<T> &_q_value) Q_DECL_NOTHROW
                                ^~~~~~
/usr/include/qt/QtCore/qatomic_cxx11.h:231:38: error: expected ‘,’ or ‘...’ before ‘<’ token
     T load(const volatile std::atomic<T> &_q_value) Q_DECL_NOTHROW
                                      ^
/usr/include/qt/QtCore/qatomic_cxx11.h:231:7: error: ‘template<class X> template<class T> static T QAtomicOps<X>::load(int)’ cannot be overloaded
     T load(const volatile std::atomic<T> &_q_value) Q_DECL_NOTHROW
       ^~~~
/usr/include/qt/QtCore/qatomic_cxx11.h:225:7: error: with ‘template<class X> template<class T> static T QAtomicOps<X>::load(int)’
     T load(const std::atomic<T> &_q_value) Q_DECL_NOTHROW
       ^~~~
/usr/include/qt/QtCore/qatomic_cxx11.h:237:30: error: ‘atomic’ in namespace ‘std’ does not name a template type
     T loadAcquire(const std::atomic<T> &_q_value) Q_DECL_NOTHROW
                              ^~~~~~
/usr/include/qt/QtCore/qatomic_cxx11.h:237:36: error: expected ‘,’ or ‘...’ before ‘<’ token
     T loadAcquire(const std::atomic<T> &_q_value) Q_DECL_NOTHROW
                                    ^
/usr/include/qt/QtCore/qatomic_cxx11.h:243:39: error: ‘atomic’ in namespace ‘std’ does not name a template type
     T loadAcquire(const volatile std::atomic<T> &_q_value) Q_DECL_NOTHROW
                                       ^~~~~~
/usr/include/qt/QtCore/qatomic_cxx11.h:243:45: error: expected ‘,’ or ‘...’ before ‘<’ token
     T loadAcquire(const volatile std::atomic<T> &_q_value) Q_DECL_NOTHROW
                                             ^
/usr/include/qt/QtCore/qatomic_cxx11.h:243:7: error: ‘template<class X> template<class T> static T QAtomicOps<X>::loadAcquire(int)’ cannot be overloaded
     T loadAcquire(const volatile std::atomic<T> &_q_value) Q_DECL_NOTHROW
       ^~~~~~~~~~~
/usr/include/qt/QtCore/qatomic_cxx11.h:237:7: error: with ‘template<class X> template<class T> static T QAtomicOps<X>::loadAcquire(int)’
     T loadAcquire(const std::atomic<T> &_q_value) Q_DECL_NOTHROW
       ^~~~~~~~~~~
/usr/include/qt/QtCore/qatomic_cxx11.h:249:21: error: ‘std::atomic’ has not been declared
     void store(std::atomic<T> &_q_value, T newValue) Q_DECL_NOTHROW
                     ^~~~~~
/usr/include/qt/QtCore/qatomic_cxx11.h:249:27: error: expected ‘,’ or ‘...’ before ‘<’ token
     void store(std::atomic<T> &_q_value, T newValue) Q_DECL_NOTHROW
                           ^
/usr/include/qt/QtCore/qatomic_cxx11.h:255:28: error: ‘std::atomic’ has not been declared
     void storeRelease(std::atomic<T> &_q_value, T newValue) Q_DECL_NOTHROW
                            ^~~~~~
/usr/include/qt/QtCore/qatomic_cxx11.h:255:34: error: expected ‘,’ or ‘...’ before ‘<’ token
     void storeRelease(std::atomic<T> &_q_value, T newValue) Q_DECL_NOTHROW
                                  ^
/usr/include/qt/QtCore/qatomic_cxx11.h:263:33: error: ‘std::atomic’ has not been declared
     static inline bool ref(std::atomic<T> &_q_value)
                                 ^~~~~~
/usr/include/qt/QtCore/qatomic_cxx11.h:263:39: error: expected ‘,’ or ‘...’ before ‘<’ token
     static inline bool ref(std::atomic<T> &_q_value)
                                       ^
/usr/include/qt/QtCore/qatomic_cxx11.h:269:35: error: ‘std::atomic’ has not been declared
     static inline bool deref(std::atomic<T> &_q_value) Q_DECL_NOTHROW
                                   ^~~~~~
/usr/include/qt/QtCore/qatomic_cxx11.h:269:41: error: expected ‘,’ or ‘...’ before ‘<’ token
     static inline bool deref(std::atomic<T> &_q_value) Q_DECL_NOTHROW
                                         ^
/usr/include/qt/QtCore/qatomic_cxx11.h:279:40: error: ‘std::atomic’ has not been declared
     static bool testAndSetRelaxed(std::atomic<T> &_q_value, T expectedValue, T newValue, T *currentValue = Q_NULLPTR) Q_DECL_NOTHROW
                                        ^~~~~~
/usr/include/qt/QtCore/qatomic_cxx11.h:279:46: error: expected ‘,’ or ‘...’ before ‘<’ token
     static bool testAndSetRelaxed(std::atomic<T> &_q_value, T expectedValue, T newValue, T *currentValue = Q_NULLPTR) Q_DECL_NOTHROW
                                              ^
In file included from /usr/include/qt/QtCore/qbasicatomic.h:53:0,
                 from /usr/include/qt/QtCore/qatomic.h:46,
                 from /usr/include/qt/QtCore/qglobal.h:1129,
                 from /usr/include/qt/QtGui/qtguiglobal.h:43,
                 from /usr/include/qt/QtWidgets/qtwidgetsglobal.h:43,
                 from /usr/include/qt/QtWidgets/qapplication.h:43,
                 from /usr/include/qt/QtWidgets/QApplication:1,
                 from hello.cpp:1:
/usr/include/qt/QtCore/qatomic_cxx11.h:288:40: error: ‘std::atomic’ has not been declared
     static bool testAndSetAcquire(std::atomic<T> &_q_value, T expectedValue, T newValue, T *currentValue = Q_NULLPTR) Q_DECL_NOTHROW
                                        ^~~~~~
/usr/include/qt/QtCore/qatomic_cxx11.h:288:46: error: expected ‘,’ or ‘...’ before ‘<’ token
     static bool testAndSetAcquire(std::atomic<T> &_q_value, T expectedValue, T newValue, T *currentValue = Q_NULLPTR) Q_DECL_NOTHROW
                                              ^
/usr/include/qt/QtCore/qatomic_cxx11.h:297:40: error: ‘std::atomic’ has not been declared
     static bool testAndSetRelease(std::atomic<T> &_q_value, T expectedValue, T newValue, T *currentValue = Q_NULLPTR) Q_DECL_NOTHROW
                                        ^~~~~~
/usr/include/qt/QtCore/qatomic_cxx11.h:297:46: error: expected ‘,’ or ‘...’ before ‘<’ token
     static bool testAndSetRelease(std::atomic<T> &_q_value, T expectedValue, T newValue, T *currentValue = Q_NULLPTR) Q_DECL_NOTHROW
                                              ^
/usr/include/qt/QtCore/qatomic_cxx11.h:306:40: error: ‘std::atomic’ has not been declared
     static bool testAndSetOrdered(std::atomic<T> &_q_value, T expectedValue, T newValue, T *currentValue = Q_NULLPTR) Q_DECL_NOTHROW
                                        ^~~~~~
/usr/include/qt/QtCore/qatomic_cxx11.h:306:46: error: expected ‘,’ or ‘...’ before ‘<’ token
     static bool testAndSetOrdered(std::atomic<T> &_q_value, T expectedValue, T newValue, T *currentValue = Q_NULLPTR) Q_DECL_NOTHROW
                                              ^
/usr/include/qt/QtCore/qatomic_cxx11.h:318:40: error: ‘std::atomic’ has not been declared
     static T fetchAndStoreRelaxed(std::atomic<T> &_q_value, T newValue) Q_DECL_NOTHROW
                                        ^~~~~~
/usr/include/qt/QtCore/qatomic_cxx11.h:318:46: error: expected ‘,’ or ‘...’ before ‘<’ token
     static T fetchAndStoreRelaxed(std::atomic<T> &_q_value, T newValue) Q_DECL_NOTHROW
                                              ^
/usr/include/qt/QtCore/qatomic_cxx11.h:324:40: error: ‘std::atomic’ has not been declared
     static T fetchAndStoreAcquire(std::atomic<T> &_q_value, T newValue) Q_DECL_NOTHROW
                                        ^~~~~~
/usr/include/qt/QtCore/qatomic_cxx11.h:324:46: error: expected ‘,’ or ‘...’ before ‘<’ token
     static T fetchAndStoreAcquire(std::atomic<T> &_q_value, T newValue) Q_DECL_NOTHROW
                                              ^
/usr/include/qt/QtCore/qatomic_cxx11.h:330:40: error: ‘std::atomic’ has not been declared
     static T fetchAndStoreRelease(std::atomic<T> &_q_value, T newValue) Q_DECL_NOTHROW
                                        ^~~~~~
/usr/include/qt/QtCore/qatomic_cxx11.h:330:46: error: expected ‘,’ or ‘...’ before ‘<’ token
     static T fetchAndStoreRelease(std::atomic<T> &_q_value, T newValue) Q_DECL_NOTHROW
                                              ^
/usr/include/qt/QtCore/qatomic_cxx11.h:336:40: error: ‘std::atomic’ has not been declared
     static T fetchAndStoreOrdered(std::atomic<T> &_q_value, T newValue) Q_DECL_NOTHROW
                                        ^~~~~~
/usr/include/qt/QtCore/qatomic_cxx11.h:336:46: error: expected ‘,’ or ‘...’ before ‘<’ token
     static T fetchAndStoreOrdered(std::atomic<T> &_q_value, T newValue) Q_DECL_NOTHROW
                                              ^
/usr/include/qt/QtCore/qatomic_cxx11.h:345:31: error: ‘std::atomic’ has not been declared
     T fetchAndAddRelaxed(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW
                               ^~~~~~
/usr/include/qt/QtCore/qatomic_cxx11.h:345:37: error: expected ‘,’ or ‘...’ before ‘<’ token
     T fetchAndAddRelaxed(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW
                                     ^
/usr/include/qt/QtCore/qatomic_cxx11.h:351:31: error: ‘std::atomic’ has not been declared
     T fetchAndAddAcquire(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW
                               ^~~~~~
/usr/include/qt/QtCore/qatomic_cxx11.h:351:37: error: expected ‘,’ or ‘...’ before ‘<’ token
     T fetchAndAddAcquire(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW
                                     ^
/usr/include/qt/QtCore/qatomic_cxx11.h:357:31: error: ‘std::atomic’ has not been declared
     T fetchAndAddRelease(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW
                               ^~~~~~
/usr/include/qt/QtCore/qatomic_cxx11.h:357:37: error: expected ‘,’ or ‘...’ before ‘<’ token
     T fetchAndAddRelease(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW
                                     ^
/usr/include/qt/QtCore/qatomic_cxx11.h:363:31: error: ‘std::atomic’ has not been declared
     T fetchAndAddOrdered(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW
                               ^~~~~~
/usr/include/qt/QtCore/qatomic_cxx11.h:363:37: error: expected ‘,’ or ‘...’ before ‘<’ token
     T fetchAndAddOrdered(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW
                                     ^
/usr/include/qt/QtCore/qatomic_cxx11.h:369:31: error: ‘std::atomic’ has not been declared
     T fetchAndSubRelaxed(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW
                               ^~~~~~
/usr/include/qt/QtCore/qatomic_cxx11.h:369:37: error: expected ‘,’ or ‘...’ before ‘<’ token
     T fetchAndSubRelaxed(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW
                                     ^
/usr/include/qt/QtCore/qatomic_cxx11.h:375:31: error: ‘std::atomic’ has not been declared
     T fetchAndSubAcquire(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW
                               ^~~~~~
/usr/include/qt/QtCore/qatomic_cxx11.h:375:37: error: expected ‘,’ or ‘...’ before ‘<’ token
     T fetchAndSubAcquire(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW
                                     ^
/usr/include/qt/QtCore/qatomic_cxx11.h:381:31: error: ‘std::atomic’ has not been declared
     T fetchAndSubRelease(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW
                               ^~~~~~
/usr/include/qt/QtCore/qatomic_cxx11.h:381:37: error: expected ‘,’ or ‘...’ before ‘<’ token
     T fetchAndSubRelease(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW
                                     ^
/usr/include/qt/QtCore/qatomic_cxx11.h:387:31: error: ‘std::atomic’ has not been declared
     T fetchAndSubOrdered(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW
                               ^~~~~~
/usr/include/qt/QtCore/qatomic_cxx11.h:387:37: error: expected ‘,’ or ‘...’ before ‘<’ token
     T fetchAndSubOrdered(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW
                                     ^
/usr/include/qt/QtCore/qatomic_cxx11.h:393:31: error: ‘std::atomic’ has not been declared
     T fetchAndAndRelaxed(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW
                               ^~~~~~
/usr/include/qt/QtCore/qatomic_cxx11.h:393:37: error: expected ‘,’ or ‘...’ before ‘<’ token
     T fetchAndAndRelaxed(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW
                                     ^
/usr/include/qt/QtCore/qatomic_cxx11.h:399:31: error: ‘std::atomic’ has not been declared
     T fetchAndAndAcquire(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW
                               ^~~~~~
/usr/include/qt/QtCore/qatomic_cxx11.h:399:37: error: expected ‘,’ or ‘...’ before ‘<’ token
     T fetchAndAndAcquire(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW
                                     ^
/usr/include/qt/QtCore/qatomic_cxx11.h:405:31: error: ‘std::atomic’ has not been declared
     T fetchAndAndRelease(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW
                               ^~~~~~
/usr/include/qt/QtCore/qatomic_cxx11.h:405:37: error: expected ‘,’ or ‘...’ before ‘<’ token
     T fetchAndAndRelease(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW
                                     ^
/usr/include/qt/QtCore/qatomic_cxx11.h:411:31: error: ‘std::atomic’ has not been declared
     T fetchAndAndOrdered(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW
                               ^~~~~~
/usr/include/qt/QtCore/qatomic_cxx11.h:411:37: error: expected ‘,’ or ‘...’ before ‘<’ token
     T fetchAndAndOrdered(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW
                                     ^
/usr/include/qt/QtCore/qatomic_cxx11.h:417:30: error: ‘std::atomic’ has not been declared
     T fetchAndOrRelaxed(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW
                              ^~~~~~
/usr/include/qt/QtCore/qatomic_cxx11.h:417:36: error: expected ‘,’ or ‘...’ before ‘<’ token
     T fetchAndOrRelaxed(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW
                                    ^
/usr/include/qt/QtCore/qatomic_cxx11.h:423:30: error: ‘std::atomic’ has not been declared
     T fetchAndOrAcquire(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW
                              ^~~~~~
/usr/include/qt/QtCore/qatomic_cxx11.h:423:36: error: expected ‘,’ or ‘...’ before ‘<’ token
     T fetchAndOrAcquire(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW
                                    ^
/usr/include/qt/QtCore/qatomic_cxx11.h:429:30: error: ‘std::atomic’ has not been declared
     T fetchAndOrRelease(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW
                              ^~~~~~
/usr/include/qt/QtCore/qatomic_cxx11.h:429:36: error: expected ‘,’ or ‘...’ before ‘<’ token
     T fetchAndOrRelease(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW
                                    ^
/usr/include/qt/QtCore/qatomic_cxx11.h:435:30: error: ‘std::atomic’ has not been declared
     T fetchAndOrOrdered(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW
                              ^~~~~~
/usr/include/qt/QtCore/qatomic_cxx11.h:435:36: error: expected ‘,’ or ‘...’ before ‘<’ token
     T fetchAndOrOrdered(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW
                                    ^
/usr/include/qt/QtCore/qatomic_cxx11.h:441:31: error: ‘std::atomic’ has not been declared
     T fetchAndXorRelaxed(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW
                               ^~~~~~
/usr/include/qt/QtCore/qatomic_cxx11.h:441:37: error: expected ‘,’ or ‘...’ before ‘<’ token
     T fetchAndXorRelaxed(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW
                                     ^
/usr/include/qt/QtCore/qatomic_cxx11.h:447:31: error: ‘std::atomic’ has not been declared
     T fetchAndXorAcquire(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW
                               ^~~~~~
/usr/include/qt/QtCore/qatomic_cxx11.h:447:37: error: expected ‘,’ or ‘...’ before ‘<’ token
     T fetchAndXorAcquire(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW
                                     ^
/usr/include/qt/QtCore/qatomic_cxx11.h:453:31: error: ‘std::atomic’ has not been declared
     T fetchAndXorRelease(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW
                               ^~~~~~
/usr/include/qt/QtCore/qatomic_cxx11.h:453:37: error: expected ‘,’ or ‘...’ before ‘<’ token
     T fetchAndXorRelease(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW
                                     ^
/usr/include/qt/QtCore/qatomic_cxx11.h:459:31: error: ‘std::atomic’ has not been declared
     T fetchAndXorOrdered(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW
                               ^~~~~~
/usr/include/qt/QtCore/qatomic_cxx11.h:459:37: error: expected ‘,’ or ‘...’ before ‘<’ token
     T fetchAndXorOrdered(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW
                                     ^
In file included from /usr/include/qt/QtCore/qbasicatomic.h:53:0,
                 from /usr/include/qt/QtCore/qatomic.h:46,
                 from /usr/include/qt/QtCore/qglobal.h:1129,
                 from /usr/include/qt/QtGui/qtguiglobal.h:43,
                 from /usr/include/qt/QtWidgets/qtwidgetsglobal.h:43,
                 from /usr/include/qt/QtWidgets/qapplication.h:43,
                 from /usr/include/qt/QtWidgets/QApplication:1,
                 from hello.cpp:1:
/usr/include/qt/QtCore/qatomic_cxx11.h: In static member function ‘static T QAtomicOps<X>::load(int)’:
/usr/include/qt/QtCore/qatomic_cxx11.h:227:16: error: ‘_q_value’ was not declared in this scope
         return _q_value.load(std::memory_order_relaxed);
                ^~~~~~~~
/usr/include/qt/QtCore/qatomic_cxx11.h:227:30: error: ‘memory_order_relaxed’ is not a member of ‘std’
         return _q_value.load(std::memory_order_relaxed);
                              ^~~
/usr/include/qt/QtCore/qatomic_cxx11.h: In static member function ‘static T QAtomicOps<X>::load(int)’:
/usr/include/qt/QtCore/qatomic_cxx11.h:233:16: error: ‘_q_value’ was not declared in this scope
         return _q_value.load(std::memory_order_relaxed);
                ^~~~~~~~
/usr/include/qt/QtCore/qatomic_cxx11.h:233:30: error: ‘memory_order_relaxed’ is not a member of ‘std’
         return _q_value.load(std::memory_order_relaxed);
                              ^~~
/usr/include/qt/QtCore/qatomic_cxx11.h: In static member function ‘static T QAtomicOps<X>::loadAcquire(int)’:
/usr/include/qt/QtCore/qatomic_cxx11.h:239:16: error: ‘_q_value’ was not declared in this scope
         return _q_value.load(std::memory_order_acquire);
                ^~~~~~~~
/usr/include/qt/QtCore/qatomic_cxx11.h:239:30: error: ‘memory_order_acquire’ is not a member of ‘std’
         return _q_value.load(std::memory_order_acquire);
                              ^~~
/usr/include/qt/QtCore/qatomic_cxx11.h: In static member function ‘static T QAtomicOps<X>::loadAcquire(int)’:
/usr/include/qt/QtCore/qatomic_cxx11.h:245:16: error: ‘_q_value’ was not declared in this scope
         return _q_value.load(std::memory_order_acquire);
                ^~~~~~~~
/usr/include/qt/QtCore/qatomic_cxx11.h:245:30: error: ‘memory_order_acquire’ is not a member of ‘std’
         return _q_value.load(std::memory_order_acquire);
                              ^~~
/usr/include/qt/QtCore/qatomic_cxx11.h: In static member function ‘static void QAtomicOps<X>::store(int)’:
/usr/include/qt/QtCore/qatomic_cxx11.h:251:9: error: ‘_q_value’ was not declared in this scope
         _q_value.store(newValue, std::memory_order_relaxed);
         ^~~~~~~~
/usr/include/qt/QtCore/qatomic_cxx11.h:251:24: error: ‘newValue’ was not declared in this scope
         _q_value.store(newValue, std::memory_order_relaxed);
                        ^~~~~~~~
/usr/include/qt/QtCore/qatomic_cxx11.h:251:34: error: ‘memory_order_relaxed’ is not a member of ‘std’
         _q_value.store(newValue, std::memory_order_relaxed);
                                  ^~~
/usr/include/qt/QtCore/qatomic_cxx11.h: In static member function ‘static void QAtomicOps<X>::storeRelease(int)’:
/usr/include/qt/QtCore/qatomic_cxx11.h:257:9: error: ‘_q_value’ was not declared in this scope
         _q_value.store(newValue, std::memory_order_release);
         ^~~~~~~~
/usr/include/qt/QtCore/qatomic_cxx11.h:257:24: error: ‘newValue’ was not declared in this scope
         _q_value.store(newValue, std::memory_order_release);
                        ^~~~~~~~
/usr/include/qt/QtCore/qatomic_cxx11.h:257:34: error: ‘memory_order_release’ is not a member of ‘std’
         _q_value.store(newValue, std::memory_order_release);
                                  ^~~
/usr/include/qt/QtCore/qatomic_cxx11.h: In static member function ‘static bool QAtomicOps<X>::ref(int)’:
/usr/include/qt/QtCore/qatomic_cxx11.h:265:18: error: ‘_q_value’ was not declared in this scope
         return ++_q_value != 0;
                  ^~~~~~~~
/usr/include/qt/QtCore/qatomic_cxx11.h: In static member function ‘static bool QAtomicOps<X>::deref(int)’:
/usr/include/qt/QtCore/qatomic_cxx11.h:271:18: error: ‘_q_value’ was not declared in this scope
         return --_q_value != 0;
                  ^~~~~~~~
In file included from /usr/include/qt/QtCore/qbasicatomic.h:53:0,
                 from /usr/include/qt/QtCore/qatomic.h:46,
                 from /usr/include/qt/QtCore/qglobal.h:1129,
                 from /usr/include/qt/QtGui/qtguiglobal.h:43,
                 from /usr/include/qt/QtWidgets/qtwidgetsglobal.h:43,
                 from /usr/include/qt/QtWidgets/qapplication.h:43,
                 from /usr/include/qt/QtWidgets/QApplication:1,
                 from hello.cpp:1:
/usr/include/qt/QtCore/qatomic_cxx11.h: In static member function ‘static bool QAtomicOps<X>::testAndSetRelaxed(int)’:
/usr/include/qt/QtCore/qatomic_cxx11.h:281:20: error: ‘_q_value’ was not declared in this scope
         bool tmp = _q_value.compare_exchange_strong(expectedValue, newValue, std::memory_order_relaxed);
                    ^~~~~~~~
/usr/include/qt/QtCore/qatomic_cxx11.h:281:53: error: ‘expectedValue’ was not declared in this scope
         bool tmp = _q_value.compare_exchange_strong(expectedValue, newValue, std::memory_order_relaxed);
                                                     ^~~~~~~~~~~~~
/usr/include/qt/QtCore/qatomic_cxx11.h:281:68: error: ‘newValue’ was not declared in this scope
         bool tmp = _q_value.compare_exchange_strong(expectedValue, newValue, std::memory_order_relaxed);
                                                                    ^~~~~~~~

.......

英语不是我的母语;请原谅输入错误。

1 个答案:

答案 0 :(得分:3)

您的屏幕截图显示错误位于名为qatomic_cxx11.h的文件中,它们与C++11中添加到语言中的功能相关。您的编译器很可能将代码视为C ++ 98,而std::atomic之类的东西并不存在。

您可能需要添加-std=c++11作为编译选项,以告诉它编译为C ++ 11。 (或者,如果您的编译器支持它,请使用std=c++14编译为C++14。)