Qt/CMake: missing ':' before identifier 'slots'`
c++, cmake, qmake, qt, windows
Solution
Your problem is most likely the inclusion of
add_definitions(-DQT_NO_KEYWORDS)
in your cmake file.
Problem
I am trying to compile the audio recorder example from Qt using my own cmake file instead of the qmake .pro file that comes with it, and I am receiving the following error: `qtaudiorecorder\audiorecorder.h(63) : error C2146: syntax error : missing ':' before identifier 'slots'` My CMakeFile: ``` find_package(Qt5 REQUIRED COMPONENTS multimedia widgets) set(CMAKE_AUTOMOC ON) set(CMAKE_INCLUDE_CURRENT_DIR ON) find_package(Qt5Widgets REQUIRED) find_package(Qt5Multimedia REQUIRED) add_definitions(-DQT_NO_KEYWORDS) add_executable(audio_recorder audiorecorder.cpp main.cpp qaudiolevel.cpp qaudiolevel.h audiorecorder.h audiorecorder.ui audiorecorder_small.ui) qt5_use_modules(audio_recorder Widgets Multimedia) ``` audiorecorder.h: ``` #ifndef AUDIORECORDER_H #define AUDIORECORDER_H #include <QMainWindow> #include <QMediaRecorder> #include <QUrl> QT_BEGIN_NAMESPACE namespace Ui { class AudioRecorder; } class QAudioRecorder; class QAudioProbe; class QAudioBuffer; QT_END_NAMESPACE class AudioRecorder : public QMainWindow { Q_OBJECT public: AudioRecorder(QWidget *parent = 0); ~AudioRecorder(); public slots: void processBuffer(const QAudioBuffer&); private slots: void setOutputLocation(); void togglePause(); void toggleRecord(); void updateState(QMediaRecorder::State); void updateProgress(qint64 pos); void displayErrorMessage(); private: Ui::AudioRecorder *ui; QAudioRecorder *audioRecorder; QAudioProbe *probe; bool outputLocationSet; }; #endif // AUDIORECORDER_H ``` I can't figure why I can't compile the Qt example with my cmake file (it compiles fine with qmake).