c++ - Qt/CMake : missing ':' before identifier 'slots' `

标签 c++ windows qt cmake qmake

我正在尝试使用我自己的 cmake 文件而不是它附带的 qmake .pro 文件从 Qt 编译录音机示例,但我收到以下错误:

qtaudiorecorder\audiorecorder.h(63):错误 C2146:语法错误:在标识符“插槽”之前缺少“:”

我的 CMake 文件:

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

我不明白为什么我不能用我的 cmake 文件编译 Qt 示例(它用 qmake 编译得很好)。

最佳答案

您的问题很可能是包含

add_definitions(-DQT_NO_KEYWORDS)

在你的 cmake 文件中。

关于c++ - Qt/CMake : missing ':' before identifier 'slots' `,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20185423/

相关文章:

c++ - Boost Djikstra 类 "boost::property_map> has no member "类型”

c++ - Qt 在 Windows 中部署应用程序需要的 dll

c++ - 谁在使用 MFC 的 VERIFY 宏?

c++ - 如何在 C++ 中绘制 3d 散点图?

windows - IIS 多个站点在同一个 ip 上,具有不同的 ssl

mysql - 在 Windows 8.1 上覆盖路径内容 - 环境变量

sql-server - 我可以在一组 Azure 服务器上运行 .bat 文件吗?

android - 如何将 OpenCV 集成到 Qt Creator Android 项目中

c++ - 如何制作一个 "True Transparent"窗口到光标,最好是在纯 QML 上? (Qt 5.7)

c++ - 初始化从 QMainWindow 类到 QDialog 类的 Ui 指针