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

Posted

技术标签:

【中文标题】为啥我不能正常使用qt在linux中编程【英文标题】:why I can't use qt to program in linux normally为什么我不能正常使用qt在linux中编程 【发布时间】:2017-05-21 03:50:48 【问题描述】:

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

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

sudo pacman -S qt5-base qt5

然后,我安装 qt-creator。

sudo pacman -S qtcreator

而且,我使用QT creator创建一个新项目(我选择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.Howerver,尝试构建和运行时出现同样的问题。

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);
                                                                    ^~~~~~~~

.......

英语不是我的母语;请原谅打字错误。

【问题讨论】:

请不要插入图片链接,而是问题中的代码和相关错误代码。 请分享.pro文件 我在 Arch Linux 上工作,我没有遇到任何问题,你可以展示你的代码和你的 .pro 文件。 执行:sudo pacman -S qt5-tools 嗯,std::atomic 在使用-std=c++11 时肯定存在。如果该标题中的 #include &lt;atomic&gt; 行不可用,您将收到错误消息。 【参考方案1】:

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

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

【讨论】:

由于这是一个 Qt 问题,正确的答案是将CONFIG += c++11CONFIG += c++14 添加到.pro 文件,删除构建文件夹,然后重新构建项目。 今天,当我再次打开qt-createor时,一切正常。我很困惑......谢谢大家。

以上是关于为啥我不能正常使用qt在linux中编程的主要内容,如果未能解决你的问题,请参考以下文章

为啥我在c编程中不能成功使用return选项?

为啥文本字段委托不能以编程方式在文本字段上使用设置文本?

为啥程序不能正常工作?

为啥我用delphi编程获取窗口句柄不成功?

为啥我不能在 react native 中以编程方式添加道具?

为啥我编译的MFC应用程序在其他电脑上不能运行?