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:

Qt Code:
  1. #include <iostream>
  2.  
  3. #include <QApplication>
  4. #include <QSerialPort>
  5.  
  6. using namespace std;
  7.  
  8. QSerialPort serial;
  9.  
  10.  
  11. int main (int argc, char *argv[])
  12. {
  13. QApplication app(argc, argv);
  14. serial.setPortName("/dev/ttyUSB0");
  15. serial.open(QIODevice::WriteOnly);
  16. serial.setBaudRate(QSerialPort::Baud19200);
  17. serial.setDataBits(QSerialPort::Data8);
  18. serial.setParity(QSerialPort::NoParity);
  19. serial.setStopBits(QSerialPort::OneStop);
  20. serial.setFlowControl(QSerialPort::NoFlowControl);
  21.  
  22.  
  23.  
  24. for (int i=0; i<100; i++)
  25. {
  26. serial.write("test");
  27. serial.flush();
  28. cout << i << endl;
  29. }
  30.  
  31. serial.close();
  32. return 0;
  33. }
To copy to clipboard, switch view to plain text mode 

And this is my .pro file:
Qt Code:
  1. QT += core serialport widgets
  2.  
  3. QT -= gui
  4.  
  5. TARGET = Timer
  6. CONFIG += console
  7. CONFIG -= app_bundle
  8.  
  9. TEMPLATE = app
  10.  
  11.  
  12. SOURCES += main.cpp
  13. QMAKE_CXXFLAGS += -std=c++0x
To copy to clipboard, switch view to plain text mode