Hello,
I need to use QSerialPort together with a USB serial adapter on Ubuntu.
This is a FT232RL which is mounted as "ttyUSB0".
Using CuteCom I can use the serial adapter and it is working fine.
Sadly with QT I am not able to access ttyUSB0.
I get no errors while compiling and executing the programm leads to an empty console window which freezes :-(
If I change ttyUSB0 to some not existing thing like ttyUSB, I get the error that he could not open the device.
So this is actually good.
But I have no Idea, how to solve my problem :-(
It would be really nice if you could help me.
Thank you very much :-)
This is the code I tried:
#include <iostream>
#include <QApplication>
#include <QSerialPort>
using namespace std;
QSerialPort serial;
int main (int argc, char *argv[])
{
serial.setPortName("/dev/ttyUSB0");
serial.setBaudRate(QSerialPort::Baud19200);
serial.setDataBits(QSerialPort::Data8);
serial.setParity(QSerialPort::NoParity);
serial.setStopBits(QSerialPort::OneStop);
serial.setFlowControl(QSerialPort::NoFlowControl);
for (int i=0; i<100; i++)
{
serial.write("test");
serial.flush();
cout << i << endl;
}
serial.close();
return 0;
}
#include <iostream>
#include <QApplication>
#include <QSerialPort>
using namespace std;
QSerialPort serial;
int main (int argc, char *argv[])
{
QApplication app(argc, argv);
serial.setPortName("/dev/ttyUSB0");
serial.open(QIODevice::WriteOnly);
serial.setBaudRate(QSerialPort::Baud19200);
serial.setDataBits(QSerialPort::Data8);
serial.setParity(QSerialPort::NoParity);
serial.setStopBits(QSerialPort::OneStop);
serial.setFlowControl(QSerialPort::NoFlowControl);
for (int i=0; i<100; i++)
{
serial.write("test");
serial.flush();
cout << i << endl;
}
serial.close();
return 0;
}
To copy to clipboard, switch view to plain text mode
And this is my .pro file:
QT += core serialport widgets
QT -= gui
TARGET = Timer
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
QMAKE_CXXFLAGS += -std=c++0x
QT += core serialport widgets
QT -= gui
TARGET = Timer
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
QMAKE_CXXFLAGS += -std=c++0x
To copy to clipboard, switch view to plain text mode
Bookmarks