繁体   English   中英

如何将QSerialPort模块添加到CMake中?

[英]How do I add QSerialPort Module into CMake?

我想将QSerialPort模块添加到CMake中。 根据我的理解,我需要将QT + = serialport添加到* .pro中。 我只想用CMake。 所以我尝试编译简单的CMake文件,但它有错误。 QtCore正在运行,因为qDebug可以毫无问题地显示。

我得到的错误是:

undefined reference to `QSerialPort::QSerialPort(QObject*)'
undefined reference to `QSerialPort::~QSerialPort()'
undefined reference to `QSerialPort::~QSerialPort()'

这是简单的main.cpp文件。

#include <iostream>
#include <QObject>
#include <QDebug>
#include <QCoreApplication>
#include <QtSerialPort/QSerialPort>

using namespace std;

int main() {
    QSerialPort serialPort; //this line gives error
    qDebug()<<"Hello Qt"; //this line is working as normal
    cout << "Hello, World!" << endl;
    return 0;
}

这是一个简单的CMake文件。

cmake_minimum_required(VERSION 3.3)
project(untitled1)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

find_package(Qt5Core  COMPONENTS Qt5SerialPort REQUIRED)

set(SOURCE_FILES main.cpp)
add_executable(untitled1 ${SOURCE_FILES})
qt5_use_modules(untitled1 Core)

谢谢@tsyvarev 你的建议解决了这个问题。 只是为了其他人的参考,我发回那些工作文件。

简单的main.cpp文件:

#include <iostream>
#include <QObject>
#include <QDebug>
#include <QCoreApplication>
#include <QtSerialPort>

using namespace std;

int main() {
    QSerialPort serialPort;
    serialPort.setPortName("ttyACM1");
    qDebug()<<"Hello Qt";
    cout << "Hello, World!" << endl;
    return 0;
}

简单的CMake文件:

cmake_minimum_required(VERSION 3.3)
project(untitled1)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

find_package(Qt5Core REQUIRED)

set(SOURCE_FILES main.cpp)
add_executable(untitled1 ${SOURCE_FILES})
qt5_use_modules(untitled1 Core SerialPort)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM