Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. serial port
Qt 6.11 is out! See what's new in the release blog

serial port

Scheduled Pinned Locked Moved Solved QML and Qt Quick
5 Posts 4 Posters 3.0k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    neda
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • K Offline
      K Offline
      kolegs
      wrote on last edited by
      #2

      Did you add

      QT += serialport
      

      in your pro file?

      1 Reply Last reply
      0
      • N Offline
        N Offline
        neda
        wrote on last edited by neda
        #3

        yes

        my project

        1 Reply Last reply
        0
        • X Offline
          X Offline
          xargs1
          wrote on last edited by
          #4

          It compiles ok for me with 64-bit Linux.

          1 Reply Last reply
          0
          • A Offline
            A Offline
            ambershark
            wrote on last edited by ambershark
            #5

            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).

            My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved