PDA

View Full Version : Qserialport issue in QT4



coss_cat
11th December 2013, 01:05
Hello,

I try to do a small test on a RS232 modem (very very old modem, but 100% functional).
I had a look on the Internet and saw a small example on Qserialport library for QT4. I installed it and when trying to compile, here are the errors:

(.text.startup+0x3e):-1: error: undefined reference to `QSerialPort::QSerialPort(QObject*)'
(.text.startup+0x66):-1: error: undefined reference to `QSerialPort::setPortName(QString const&)'
(.text.startup+0x8e):-1: error: undefined reference to `QSerialPort::setBaudRate(int, QFlags<QSerialPort::Direction>)'
(.text.startup+0x9e):-1: error: undefined reference to `QSerialPort::setDataBits(QSerialPort::DataBits)'
...
etc.

Same err. for all related QserialPort class members :(

Before posting here I had a look on other posts and internet, so I added also QT += serialport in the .pro file, but same result


Here are my files:




// main.cpp

#include <QtCore/QCoreApplication>
#include <QtSerialPort/QSerialPort>
#include <QtSerialPort/QSerialPortInfo>


int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);

QSerialPort serial;
serial.setPortName("com1");
serial.setBaudRate(QSerialPort::Baud9600);
serial.setDataBits(QSerialPort::Data8);
serial.setParity(QSerialPort::NoParity);
serial.setStopBits(QSerialPort::OneStop);
serial.setFlowControl(QSerialPort::NoFlowControl);
serial.open(QIODevice::ReadWrite);
serial.write("firs string to serial");

serial.close();

return a.exec();
}






and the .pro file|:




#-------------------------------------------------
#
# Project created by QtCreator 2013-12-11T00:53:45
#
#-------------------------------------------------

QT += core serialport

QT -= gui

TARGET = serial
CONFIG += console
CONFIG -= app_bundle

TEMPLATE = app


SOURCES += main.cpp \
serial_intf.cpp

HEADERS += \
serial_intf.h





Don't consider serial_intf.h It is intended for future use, but contains nothiing in it

Thank you.

Costin

zaphod.b
11th December 2013, 01:46
The linker doesn't find the QtSerialPort library. Check the linker options and verify the lib is found under the according path. If it isn't your Qt installation may be configured such that the lib isn't built.

What's your platform?
How did you install Qt?
How do you invoke the linker (IDE/command line/...)?

kuzulis
11th December 2013, 08:11
For Qt4 need add CONFIG += serialport instead of QT += serialport. Please be more attentive and read Wiki (http://qt-project.org/wiki/QtSerialPort).

coss_cat
11th December 2013, 19:11
Hello kuzulis, your solution worked well. Thank you.



Costin