serial port
Solved
QML and Qt Quick
-
hi
I'm using Qt version 5.5.1 from windows 8.1.
i use this code for for receiving data asynchronously over the selected serial port.
but i have error.main.cpp:
#include <QApplication> #include <QQmlApplicationEngine> #include <QtSerialPort/QSerialPort> #include "serialportreader.h" int main(int argc, char *argv[]) { QApplication app(argc, argv); QQmlApplicationEngine engine; engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); QStringList argumentList = QCoreApplication::arguments(); QTextStream standardOutput(stdout); int argumentCount = QCoreApplication::arguments().size(); if (argumentCount == 1) { standardOutput << QObject::tr("Usage: %1 <serialportname> [baudrate]").arg(argumentList.first()) << endl; return 1; } QSerialPort serialPort; QString serialPortName = argumentList.at(1); serialPort.setPortName(serialPortName); int serialPortBaudRate = (argumentCount > 2) ? argumentList.at(2).toInt() : QSerialPort::Baud9600; serialPort.setBaudRate(serialPortBaudRate); if (!serialPort.open(QIODevice::ReadOnly)) { standardOutput << QObject::tr("Failed to open port %1, error: %2").arg(serialPortName).arg(serialPort.errorString()) << endl; return 1; } SerialPortReader serialPortReader(&serialPort); return app.exec(); }
error:
main.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl QSerialPort::QSerialPort(class QObject *)" (__imp_??0QSerialPort@@QEAA@PEAVQObject@@@Z) referenced in function main
and similar errors
-
yes
-
Builds for me using WIndows 8.1 and Qt 5.5.0 (mingw):
15:26:10: Running steps for project serialport... 15:26:10: Starting: "C:\Qt\5.5\mingw492_32\bin\qmake.exe" E:\serialport\serialport.pro -r -spec win32-g++ "CONFIG+=debug" "CONFIG+=declarative_debug" "CONFIG+=qml_debug" 15:26:11: The process "C:\Qt\5.5\mingw492_32\bin\qmake.exe" exited normally. 15:26:11: Starting: "C:\Qt\Tools\mingw492_32\bin\mingw32-make.exe" C:/Qt/Tools/mingw492_32/bin/mingw32-make -f Makefile.Debug mingw32-make[1]: Entering directory 'E:/build-serialport-Desktop_Qt_5_5_0_MinGW_32bit-Debug' g++ -c -pipe -fno-keep-inline-dllexport -g -frtti -Wall -Wextra -fexceptions -mthreads -DUNICODE -DQT_QML_DEBUG -DQT_DECLARATIVE_DEBUG -DQT_QUICK_LIB -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_QML_LIB -DQT_NETWORK_LIB -DQT_SERIALPORT_LIB -DQT_CORE_LIB -I..\serialport -I. -IC:\Qt\5.5\mingw492_32\include -IC:\Qt\5.5\mingw492_32\include\QtQuick -IC:\Qt\5.5\mingw492_32\include\QtWidgets -IC:\Qt\5.5\mingw492_32\include\QtGui -IC:\Qt\5.5\mingw492_32\include\QtANGLE -IC:\Qt\5.5\mingw492_32\include\QtQml -IC:\Qt\5.5\mingw492_32\include\QtNetwork -IC:\Qt\5.5\mingw492_32\include\QtSerialPort -IC:\Qt\5.5\mingw492_32\include\QtCore -Idebug -IC:\Qt\5.5\mingw492_32\mkspecs\win32-g++ -o debug\main.o ..\serialport\main.cpp g++ -c -pipe -fno-keep-inline-dllexport -g -frtti -Wall -Wextra -fexceptions -mthreads -DUNICODE -DQT_QML_DEBUG -DQT_DECLARATIVE_DEBUG -DQT_QUICK_LIB -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_QML_LIB -DQT_NETWORK_LIB -DQT_SERIALPORT_LIB -DQT_CORE_LIB -I..\serialport -I. -IC:\Qt\5.5\mingw492_32\include -IC:\Qt\5.5\mingw492_32\include\QtQuick -IC:\Qt\5.5\mingw492_32\include\QtWidgets -IC:\Qt\5.5\mingw492_32\include\QtGui -IC:\Qt\5.5\mingw492_32\include\QtANGLE -IC:\Qt\5.5\mingw492_32\include\QtQml -IC:\Qt\5.5\mingw492_32\include\QtNetwork -IC:\Qt\5.5\mingw492_32\include\QtSerialPort -IC:\Qt\5.5\mingw492_32\include\QtCore -Idebug -IC:\Qt\5.5\mingw492_32\mkspecs\win32-g++ -o debug\serialportreader.o ..\serialport\serialportreader.cpp C:\Qt\5.5\mingw492_32\bin\rcc.exe -name qml ..\serialport\qml.qrc -o debug\qrc_qml.cpp g++ -c -pipe -fno-keep-inline-dllexport -g -frtti -Wall -Wextra -fexceptions -mthreads -DUNICODE -DQT_QML_DEBUG -DQT_DECLARATIVE_DEBUG -DQT_QUICK_LIB -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_QML_LIB -DQT_NETWORK_LIB -DQT_SERIALPORT_LIB -DQT_CORE_LIB -I..\serialport -I. -IC:\Qt\5.5\mingw492_32\include -IC:\Qt\5.5\mingw492_32\include\QtQuick -IC:\Qt\5.5\mingw492_32\include\QtWidgets -IC:\Qt\5.5\mingw492_32\include\QtGui -IC:\Qt\5.5\mingw492_32\include\QtANGLE -IC:\Qt\5.5\mingw492_32\include\QtQml -IC:\Qt\5.5\mingw492_32\include\QtNetwork -IC:\Qt\5.5\mingw492_32\include\QtSerialPort -IC:\Qt\5.5\mingw492_32\include\QtCore -Idebug -IC:\Qt\5.5\mingw492_32\mkspecs\win32-g++ -o debug\qrc_qml.o debug\qrc_qml.cpp C:\Qt\5.5\mingw492_32\bin\moc.exe -DUNICODE -DQT_QML_DEBUG -DQT_DECLARATIVE_DEBUG -DQT_QUICK_LIB -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_QML_LIB -DQT_NETWORK_LIB -DQT_SERIALPORT_LIB -DQT_CORE_LIB -D__GNUC__ -DWIN32 -IC:/Qt/5.5/mingw492_32/mkspecs/win32-g++ -IE:/serialport -IC:/Qt/5.5/mingw492_32/include -IC:/Qt/5.5/mingw492_32/include/QtQuick -IC:/Qt/5.5/mingw492_32/include/QtWidgets -IC:/Qt/5.5/mingw492_32/include/QtGui -IC:/Qt/5.5/mingw492_32/include/QtANGLE -IC:/Qt/5.5/mingw492_32/include/QtQml -IC:/Qt/5.5/mingw492_32/include/QtNetwork -IC:/Qt/5.5/mingw492_32/include/QtSerialPort -IC:/Qt/5.5/mingw492_32/include/QtCore -I. ..\serialport\serialportreader.h -o debug\moc_serialportreader.cpp g++ -c -pipe -fno-keep-inline-dllexport -g -frtti -Wall -Wextra -fexceptions -mthreads -DUNICODE -DQT_QML_DEBUG -DQT_DECLARATIVE_DEBUG -DQT_QUICK_LIB -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_QML_LIB -DQT_NETWORK_LIB -DQT_SERIALPORT_LIB -DQT_CORE_LIB -I..\serialport -I. -IC:\Qt\5.5\mingw492_32\include -IC:\Qt\5.5\mingw492_32\include\QtQuick -IC:\Qt\5.5\mingw492_32\include\QtWidgets -IC:\Qt\5.5\mingw492_32\include\QtGui -IC:\Qt\5.5\mingw492_32\include\QtANGLE -IC:\Qt\5.5\mingw492_32\include\QtQml -IC:\Qt\5.5\mingw492_32\include\QtNetwork -IC:\Qt\5.5\mingw492_32\include\QtSerialPort -IC:\Qt\5.5\mingw492_32\include\QtCore -Idebug -IC:\Qt\5.5\mingw492_32\mkspecs\win32-g++ -o debug\moc_serialportreader.o debug\moc_serialportreader.cpp g++ -Wl,-subsystem,console -mthreads -o debug\serialport.exe debug/main.o debug/serialportreader.o debug/qrc_qml.o debug/moc_serialportreader.o -LC:/Qt/5.5/mingw492_32/lib -lQt5Quickd -lQt5Widgetsd -lQt5Guid -lQt5Qmld -lQt5Networkd -lQt5SerialPortd -lQt5Cored mingw32-make[1]: Leaving directory 'E:/build-serialport-Desktop_Qt_5_5_0_MinGW_32bit-Debug' 15:26:14: The process "C:\Qt\Tools\mingw492_32\bin\mingw32-make.exe" exited normally. 15:26:14: Elapsed time: 00:05.
Edit: Builds on my native Linux side as well (gentoo 64-bit).