由于未定义QSerialPortInfo方法引用,无法编译
Cannot compile due to undefined QSerialPortInfo method references
我在Qt Creator上遇到QSerialPortInfo
的一个奇怪问题。为了尽可能简单地说明这个问题,让我们看看这个小代码片段。
.pro
我当然包括了CONFIG += serialport
。
main.cpp
#include <QGuiApplication>
#include <QTimer>
#include <QtSerialPort/QSerialPort>
#include <QtSerialPort/QSerialPortInfo>
int main(int argc, char *argv[])
{
QGuiApplication a(argc, argv);
QList<QSerialPortInfo> ports = QSerialPortInfo::availablePorts();
QList<QSerialPortInfo>::iterator i;
for(i = ports.begin(); i != ports.end(); i++)
{
printf("Port:n");
printf(" - Name: %sn", (*i).portName().toStdString().data());
printf(" - Description: %sn", (*i).description().toStdString().data());
printf(" - Manufacturer: %sn", (*i).manufacturer().toStdString().data());
printf(" - Serial number: %sn", (*i).serialNumber().toStdString().data());
printf(" - System location: %sn", (*i).systemLocation().toStdString().data());
printf("n");
QTimer::singleShot(0, QCoreApplication::instance(), SLOT(quit()));
return a.exec();
}
这是一个非常简单的例子,说明了如何查询系统中连接到它的设备,但是当我在QtCreator上编译它时,make
会将所有方法报告为未定义。
undefined reference to `QSerialPortInfo::availablePorts()'
undefined reference to `QSerialPortInfo::portName() const'
undefined reference to `QSerialPortInfo::description() const'
undefined reference to `QSerialPortInfo::manufacturer() const'
undefined reference to `QSerialPortInfo::serialNumber() const'
undefined reference to `QSerialPortInfo::systemLocation()'
还尝试了#include <QtSerialPort/qserialportinfo.h>
以确定,但没有更改。
我还看了一下,QSerialPort文件存在于Qt源文件夹下,我相信我已经包含了对它的所有必要引用。
我很困惑,不知道我错过了什么。
试试这个:
QT += serialport
而不是这个:
CONFIG += serialport
链接:http://doc.qt.io/qt-5/qserialportinfo.html
相关文章:
- 编译C++时未定义的引用
- 我的项目不会像"undefined reference to `grpc::g_core_codegen_interface'"那样使用未定义的引用错误进行编译
- 编译时的 CImg 库返回对"__imp_SetDIBitsToDevice"的未定义引用
- 非类型指针和引用模板参数,以及在编译时如何/为什么解析它们.c++
- 未定义的引用 .. 使用 OpenCV 编译 C++ 代码时,从命令行
- C++ 中的编译错误:未定义对"主"的引用 collect2:错误:ld 返回 1 个退出状态
- 在编译它时显示未定义的引用
- 如何编译使用循环引用的代码?
- 编译问题:在函数"_start"中:未定义对"主"的引用 collect2:错误:ld 返回 1 个退出状态
- 编译 libfluid 样本控制器时对"event_base_del_virtual"的未定义引用
- 为什么我的C++代码无法编译,出现未定义的引用错误
- 在其他容器中使用 boost::container::static_vector 时,GCC 编译错误"将'const s'绑定到类型's&'的引用丢弃限定符"
- C++ 为什么在定义的编译和链接之前引用外部实例的程序
- 在 Linux 上编译 - 在函数 '_start' 中:(.text+0x20):对 'main' 的未定义引用
- 在Linux/Ubuntu中编译openCV应用程序时,如何解决未定义的引用cv:..?
- 带有引用的std::tuple在clang中编译失败,但在gcc中编译失败
- 当我编译引用 std::ostream 时,我有一个奇怪的错误弹出
- .so中存在的符号已编译.o引用了它,但链接失败
- 不同计算机的算法与预编译引用实现的速度比不同
- 在x86中编译引用C++/CLI DLL的C#项目时,MSBuild无法生成