QT QOverload没有在Travis CI上声明在这个范围内

QT QOverload was not declared in this scope on Travis CI

本文关键字:声明 范围内 Travis QOverload QT CI      更新时间:2023-10-16

所以我目前正在尝试为 GitHub 上的 Qt 项目设置 Travis CI,但是我在编译时遇到错误。它在我的(Windows)机器上运行良好,但在Ubuntu Travis CI构建上则不然。

我特别遇到的问题是

g++ -c -m64 -pipe -O2 -std=c++0x -Wall -W -D_REENTRANT -fPIE -DQT_DEPRECATED_WARNINGS -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_SQL_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I/usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++-64 -I. -I/usr/include/qt5 -I/usr/include/qt5/QtWidgets -I/usr/include/qt5/QtSql -I/usr/include/qt5/QtGui -I/usr/include/qt5/QtCore -I. -I. -o BacklogManager.o BacklogManager/BacklogManager.cpp
BacklogManager/BacklogManager.cpp: In member function ‘void BacklogManager::ConnectActions()’:
BacklogManager/BacklogManager.cpp:267:5: error: ‘QOverload’ was not declared in this scope
     QOverload<const QString&>::of(&QComboBox::currentIndexChanged), this,
     ^
BacklogManager/BacklogManager.cpp:267:15: error: expected primary-expression before ‘const’
     QOverload<const QString&>::of(&QComboBox::currentIndexChanged), this,

同样,这在我的机器上完美运行。我已经包含在BacklogManager.cpp中。我只是不确定为什么这没有在特拉维斯 CI 的那个范围内定义。

.

travis.yml

#-------------------------------------------------
#
# Project created by QtCreator 2017-10-25T12:09:46
#
#-------------------------------------------------
QT       += core gui sql
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = BacklogManager
TEMPLATE = app
CONFIG += c++11
# The following define makes your compiler emit warnings if you use
# any feature of Qt which has 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 += 
    BacklogManager/main.cpp 
    BacklogManager/GeneratedFiles/qrc_BacklogManagerForm.cpp 
    BacklogManager/AboutForm.cpp 
    BacklogManager/BacklogManager.cpp 
    BacklogManager/FilterForm.cpp 
    BacklogManager/GameCollection.cpp 
    BacklogManager/GameForm.cpp 
    BacklogManager/GameStats.cpp 
    BacklogManager/ImportCSV.cpp 
    BacklogManager/SQLDatabase.cpp 
    BacklogManager/TableWidget.cpp 
    BacklogManager/Utilities.cpp
HEADERS += 
    BacklogManager/GeneratedFiles/ui_AboutForm.h 
    BacklogManager/GeneratedFiles/ui_BacklogManagerForm.h 
    BacklogManager/GeneratedFiles/ui_FilterForm.h 
    BacklogManager/GeneratedFiles/ui_GameForm.h 
    BacklogManager/GeneratedFiles/ui_GameStats.h 
    BacklogManager/AboutForm.h 
    BacklogManager/BacklogManager.h 
    BacklogManager/Defines.h 
    BacklogManager/FilterForm.h 
    BacklogManager/GameCollection.h 
    BacklogManager/GameForm.h 
    BacklogManager/GameStats.h 
    BacklogManager/ImportCSV.h 
    BacklogManager/SQLDatabase.h 
    BacklogManager/TableWidget.h 
    BacklogManager/Utilities.h 
FORMS += 
    BacklogManager/FilterForm.ui 
    BacklogManager/BacklogManagerForm.ui 
    BacklogManager/AboutForm.ui 
    BacklogManager/GameForm.ui 
    BacklogManager/GameStats.ui 
    BacklogManager/AddGame.ui

(缩短)Travis CI 构建日志

[0K$ git checkout -qf FETCH_HEAD
travis_fold:end:git.checkout
[0K$ export CXX=g++
$ export CC=gcc
$ gcc --version
gcc (Ubuntu 4.8.4-2ubuntu1~14.04.3) 4.8.4
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
travis_fold:start:before_install.1
[0Ktravis_time:start:0688fd46
[0K$ sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
gpg: keyring `/tmp/tmpisgvwm1_/secring.gpg' created
gpg: keyring `/tmp/tmpisgvwm1_/pubring.gpg' created
gpg: requesting key BA9EF27F from hkp server keyserver.ubuntu.com
gpg: /tmp/tmpisgvwm1_/trustdb.gpg: trustdb created
gpg: key BA9EF27F: public key "Launchpad Toolchain builds" imported
gpg: Total number processed: 1
gpg:               imported: 1  (RSA: 1)
OK
travis_time:end:0688fd46:start=1509290965413243222,finish=1509290967005300406,duration=1592057184
[0Ktravis_fold:end:before_install.1
[0Ktravis_fold:start:before_install.2
[0Ktravis_time:start:0457fc09
[0K$ sudo add-apt-repository ppa:beineri/opt-qt592-trusty -y
gpg: keyring `/tmp/tmpx6oia2wd/secring.gpg' created
gpg: keyring `/tmp/tmpx6oia2wd/pubring.gpg' created
gpg: requesting key E9977759 from hkp server keyserver.ubuntu.com
gpg: /tmp/tmpx6oia2wd/trustdb.gpg: trustdb created
gpg: key E9977759: public key "Launchpad PPA for Stephan Binner" imported
gpg: Total number processed: 1
gpg:               imported: 1  (RSA: 1)
OK
travis_time:end:0457fc09:start=1509290967009916994,finish=1509290968526560850,duration=1516643856
[0Ktravis_fold:end:before_install.2
[0Ktravis_fold:start:before_install.3
[0Ktravis_time:start:292ac127
[0K$ sudo apt-get update -qq
W: http://dl.hhvm.com/ubuntu/dists/trusty/InRelease: Signature by key 36AEF64D0207E7EEE352D4875A16E7281BE7A449 uses weak digest algorithm (SHA1)
W: http://ppa.launchpad.net/couchdb/stable/ubuntu/dists/trusty/Release.gpg: Signature by key 15866BAFD9BCC4F3C1E0DFC7D69548E1C17EAB57 uses weak digest algorithm (SHA1)
travis_time:end:292ac127:start=1509290968531061520,finish=1509290974280712646,duration=5749651126
[0Ktravis_fold:end:before_install.3
[0Ktravis_fold:start:before_install.4
[0Ktravis_time:start:0fcaba98
[0K$ sudo apt-get -qq install qt5-default qt59base qt59declarative libqt5svg5-dev qttools5-dev qttools5-dev-tools
 update-alternatives: using /usr/lib/x86_64-linux-gnu/mir/clientplatform/mesa/ld.so.conf to provide /etc/ld.so.conf.d/x86_64-linux-gnu_mirclientplatform.conf (x86_64-linux-gnu_mirclientplatform_conf) in auto mode
Processing triggers for libc-bin (2.19-0ubuntu6.13) ...
travis_time:end:0fcaba98:start=1509290974285317621,finish=1509291036193996862,duration=61908679241
[0Ktravis_fold:end:before_install.4
[0Ktravis_fold:start:before_install.5
[0Ktravis_time:start:07c7d119
[0K$ export QMAKE=/usr/lib/x86_64-linux-gnu/qt5/bin/qmake
travis_time:end:07c7d119:start=1509291036198658415,finish=1509291036202433724,duration=3775309
[0Ktravis_fold:end:before_install.5
[0Ktravis_time:start:09d09b0a
[0K$ qmake
travis_time:end:09d09b0a:start=1509291036207049765,finish=1509291036282556254,duration=75506489
[0K
[32;1mThe command "qmake" exited with 0.[0m
travis_time:start:1c2447c8
[0K$ make
/usr/lib/x86_64-linux-gnu/qt5/bin/uic BacklogManager/FilterForm.ui -o ui_FilterForm.h
/usr/lib/x86_64-linux-gnu/qt5/bin/uic BacklogManager/BacklogManagerForm.ui -o ui_BacklogManagerForm.h
/usr/lib/x86_64-linux-gnu/qt5/bin/uic BacklogManager/AboutForm.ui -o ui_AboutForm.h
/usr/lib/x86_64-linux-gnu/qt5/bin/uic BacklogManager/GameForm.ui -o ui_GameForm.h
/usr/lib/x86_64-linux-gnu/qt5/bin/uic BacklogManager/GameStats.ui -o ui_GameStats.h
/usr/lib/x86_64-linux-gnu/qt5/bin/uic BacklogManager/AddGame.ui -o ui_AddGame.h
g++ -c -m64 -pipe -O2 -std=c++0x -Wall -W -D_REENTRANT -fPIE -DQT_DEPRECATED_WARNINGS -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_SQL_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I/usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++-64 -I. -I/usr/include/qt5 -I/usr/include/qt5/QtWidgets -I/usr/include/qt5/QtSql -I/usr/include/qt5/QtGui -I/usr/include/qt5/QtCore -I. -I. -o main.o BacklogManager/main.cpp
g++ -c -m64 -pipe -O2 -std=c++0x -Wall -W -D_REENTRANT -fPIE -DQT_DEPRECATED_WARNINGS -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_SQL_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I/usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++-64 -I. -I/usr/include/qt5 -I/usr/include/qt5/QtWidgets -I/usr/include/qt5/QtSql -I/usr/include/qt5/QtGui -I/usr/include/qt5/QtCore -I. -I. -o qrc_BacklogManagerForm.o BacklogManager/GeneratedFiles/qrc_BacklogManagerForm.cpp
g++ -c -m64 -pipe -O2 -std=c++0x -Wall -W -D_REENTRANT -fPIE -DQT_DEPRECATED_WARNINGS -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_SQL_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I/usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++-64 -I. -I/usr/include/qt5 -I/usr/include/qt5/QtWidgets -I/usr/include/qt5/QtSql -I/usr/include/qt5/QtGui -I/usr/include/qt5/QtCore -I. -I. -o AboutForm.o BacklogManager/AboutForm.cpp
g++ -c -m64 -pipe -O2 -std=c++0x -Wall -W -D_REENTRANT -fPIE -DQT_DEPRECATED_WARNINGS -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_SQL_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I/usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++-64 -I. -I/usr/include/qt5 -I/usr/include/qt5/QtWidgets -I/usr/include/qt5/QtSql -I/usr/include/qt5/QtGui -I/usr/include/qt5/QtCore -I. -I. -o BacklogManager.o BacklogManager/BacklogManager.cpp
BacklogManager/BacklogManager.cpp: In member function ‘void BacklogManager::ConnectActions()’:
BacklogManager/BacklogManager.cpp:267:5: error: ‘QOverload’ was not declared in this scope
     QOverload<const QString&>::of(&QComboBox::currentIndexChanged), this,
     ^
BacklogManager/BacklogManager.cpp:267:15: error: expected primary-expression before ‘const’
     QOverload<const QString&>::of(&QComboBox::currentIndexChanged), this,
               ^
make: *** [BacklogManager.o] Error 1
travis_time:end:1c2447c8:start=1509291036287279268,finish=1509291040070812417,duration=3783533149
[0K
[31;1mThe command "make" exited with 2.[0m
Done. Your build exited with 1.

根据您使用的 PPA 的 PPA 描述,Qt5.9 将安装在 /opt/qt59 下,但 travis 输出显示 export QMAKE=/usr/lib/x86_64-linux-gnu/qt5/bin/qmake .

它猜测这是Ubuntu附带的Qt版本的路径,它可能太旧了,无法包含QOverload 。将该路径更改为/opt/qt59/bin/qmake应该可以解决您的问题。