Results 1 to 8 of 8

Thread: SerialProgramming qextserialport or QSerialDevice?

  1. #1
    Join Date
    Oct 2011
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default SerialProgramming qextserialport or QSerialDevice?

    Hello,

    I just started programming QT4 on an Windows 7 64bit OS and now I want to use the SerialPort.
    I've already read a lot Thread in several forums, and I found the QextSerialPort and the QSerialDevice.
    Would QSerialDevice be better, because QextSerialPort is not longer developed?

    I downloaded both an tryed to compiled them. Compiling QextSerialPort gives me a libqextserialport.a and a qextserialport.dll, but do I have to do with these files?

    Compiling QSerialPort gives me a few errors. Here is the Build Log:
    Qt Code:
    1. Führe Build-Schritte für Projekt BuildLibrary aus... //Translation: Building Project BuildLibrary
    2. Unveränderte Konfiguration, qmake-Schritt wird übersprungen. //Translation: Config not changed, skipping qmake
    3. Starte "C:\QtSDK\mingw\bin\mingw32-make.exe"
    4. cd src/ && C:/QtSDK/mingw/bin/mingw32-make -f Makefile
    5. mingw32-make[1]: Entering directory `c:/Users/Philipp/Documents/Qt/QSerialPort/BuildLibrary-build-desktop-Qt_4_7_4_for_Desktop_-_MinGW_4_4__Qt_SDK__Release/src'
    6. c:/QtSDK/mingw/bin/mingw32-make -f Makefile.Release
    7. mingw32-make[2]: Entering directory `c:/Users/Philipp/Documents/Qt/QSerialPort/BuildLibrary-build-desktop-Qt_4_7_4_for_Desktop_-_MinGW_4_4__Qt_SDK__Release/src'
    8. g++ -c -O2 -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_NO_DEBUG -DQT_CORE_LIB -DQT_HAVE_MMX -DQT_HAVE_3DNOW -DQT_HAVE_SSE -DQT_HAVE_MMXEXT -DQT_HAVE_SSE2 -DQT_THREAD_SUPPORT -I'c:/QtSDK/Desktop/Qt/4.7.4/mingw/include/QtCore' -I'c:/QtSDK/Desktop/Qt/4.7.4/mingw/include' -I'../../qserialdevice-qserialdevice/src/qserialdevice' -I'../../qserialdevice-qserialdevice/src/qserialdeviceenumerator' -I'c:/QtSDK/Desktop/Qt/4.7.4/mingw/include/ActiveQt' -I'build/moc' -I'../../qserialdevice-qserialdevice/src' -I'.' -I'c:/QtSDK/Desktop/Qt/4.7.4/mingw/mkspecs/win32-g++' -o build/obj/abstractserialnotifier.o ../../qserialdevice-qserialdevice/src/qserialdevice/abstractserialnotifier.cpp
    9. In file included from ../../qserialdevice-qserialdevice/src/qserialdevice/abstractserialnotifier.cpp:2:
    10. ../../qserialdevice-qserialdevice/src/qserialdevice/nativeserialnotifier.h:8:50: error: QtCore/private/qwineventnotifier_p.h: No such file or directory
    11. In file included from ../../qserialdevice-qserialdevice/src/qserialdevice/abstractserialnotifier.cpp:2:
    12. ../../qserialdevice-qserialdevice/src/qserialdevice/nativeserialnotifier.h:18: error: expected class-name before ',' token
    13. ../../qserialdevice-qserialdevice/src/qserialdevice/nativeserialnotifier.h:37: error: 'OVERLAPPED' in namespace '::' does not name a type
    14. ../../qserialdevice-qserialdevice/src/qserialdevice/nativeserialnotifier.h:38: error: 'DWORD' in namespace '::' does not name a type
    15. ../../qserialdevice-qserialdevice/src/qserialdevice/nativeserialnotifier.h:39: error: 'DWORD' in namespace '::' does not name a type
    16. mingw32-make[2]: Leaving directory `c:/Users/Philipp/Documents/Qt/QSerialPort/BuildLibrary-build-desktop-Qt_4_7_4_for_Desktop_-_MinGW_4_4__Qt_SDK__Release/src'
    17. mingw32-make[1]: Leaving directory `c:/Users/Philipp/Documents/Qt/QSerialPort/BuildLibrary-build-desktop-Qt_4_7_4_for_Desktop_-_MinGW_4_4__Qt_SDK__Release/src'
    18. mingw32-make[2]: *** [build/obj/abstractserialnotifier.o] Error 1
    19. mingw32-make[1]: *** [release] Error 2
    20. mingw32-make: *** [sub-src-make_default] Error 2
    21. Der Prozess "C:\QtSDK\mingw\bin\mingw32-make.exe" wurde mit dem Rückgabewert 2 beendet. //Returns 2
    22. Fehler beim Erstellen des Projekts BuildLibrary(Ziel: Desktop) //Error while compiling Project BuildLibrary (Target: Desktop)
    23. Bei der Ausführung von Build-Schritt 'Make' //At builing step 'Make'
    To copy to clipboard, switch view to plain text mode 

    What could be wrong?

    Greeting
    Philipp

  2. #2
    Join Date
    Jan 2009
    Location
    Russia
    Posts
    309
    Thanks
    2
    Thanked 43 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: SerialProgramming qextserialport or QSerialDevice?

    error: QtCore/private/qwineventnotifier_p.h: No such file or directory
    Search in Google (or in this forum) will save the newbies!

    UPD: take while sources here

  3. #3
    Join Date
    Oct 2011
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: SerialProgramming qextserialport or QSerialDevice?

    Ok thank you, it's working now, I read this:
    http://code.google.com/p/qextserialp...s/detail?id=91

    But where do I have to copie the files now? I want to make the lib available for all my projects.
    I have now a libqserialdevice.a, 4 cpp files in the moc folder and the object files.

    Greetings
    Philipp

  4. #4
    Join Date
    Jan 2009
    Location
    Russia
    Posts
    309
    Thanks
    2
    Thanked 43 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: SerialProgramming qextserialport or QSerialDevice?

    Plug directly over *.pri, without building the libraries, see the examples /test/guiapp.
    So it will be easier.

    Or, if you build the library, you need:
    abstractserial.h
    serialdeviceenumerator.h
    qserialdevice_global.h
    libqserialdevice.a(dll)

    Copy these files to any location of your project
    such as headers in /include, library in /lib and in *. pro project file write these paths.

    To not take qserialdevice_global.h - copy its contents to abstractserial.h and serialdeviceenumerator.h
    Last edited by kuzulis; 24th October 2011 at 13:05.

  5. #5
    Join Date
    Oct 2011
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: SerialProgramming qextserialport or QSerialDevice?

    Hello,

    thank you, it's working now.
    I wrote a smal Test app, and I you copied the code from one QSerialDevice Test app.
    But the programm crashes everytime I start it, because theres something wrong. The debugger shows me the qmap.h file in line 813:
    Qt Code:
    1. template <class Key, class T>
    2. Q_OUTOFLINE_TEMPLATE QList<Key> QMap<Key, T>::keys() const
    3. {
    4. QList<Key> res;
    5. res.reserve(size());
    6. const_iterator i = begin();
    7. while (i != end()) {
    8. res.append(i.key());
    9. ++i;
    10. }
    11. return res;
    12. }
    To copy to clipboard, switch view to plain text mode 

    Here is my code:
    main.cpp
    Qt Code:
    1. #include <QtGui/QApplication>
    2. #include "mainwindow.h"
    3.  
    4.  
    5. int main(int argc, char *argv[])
    6. {
    7. QApplication a(argc, argv);
    8. MainWindow w;
    9. w.show();
    10.  
    11. return a.exec();
    12. }
    To copy to clipboard, switch view to plain text mode 

    mainwindow.h
    Qt Code:
    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3.  
    4. #include <QMainWindow>
    5. #include "serialdeviceenumerator.h"
    6. #include "abstractserial.h"
    7.  
    8. class AbstractSerial;
    9. class SerialDeviceEnumerator;
    10.  
    11.  
    12. namespace Ui {
    13. class MainWindow;
    14. }
    15.  
    16. class MainWindow : public QMainWindow
    17. {
    18. Q_OBJECT
    19.  
    20. public:
    21. explicit MainWindow(QWidget *parent = 0);
    22. ~MainWindow();
    23.  
    24. private:
    25. Ui::MainWindow *ui;
    26. SerialDeviceEnumerator *enumerator;
    27. AbstractSerial *serial;
    28.  
    29. //Inits
    30. //void initEnumerator();
    31. //void deinitEnumerator();
    32. //void initSerial();
    33.  
    34. public slots:
    35. void procEnumerate(const QStringList &l);
    36. //void procSerialMessages(const QString &msg, QDateTime dt);
    37. //void procSerialDataReceive();
    38.  
    39. };
    40.  
    41. #endif // MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 

    mainwindow.cpp
    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3.  
    4.  
    5. MainWindow::MainWindow(QWidget *parent) :
    6. QMainWindow(parent),
    7. ui(new Ui::MainWindow)
    8. {
    9. ui->setupUi(this);
    10.  
    11. //Enumerator
    12. if(!this->enumerator)
    13. this->enumerator = SerialDeviceEnumerator::instance();
    14. connect(this->enumerator,SIGNAL(hasChanged(QStringList)),this,SLOT(procEnumerate(QStringList)));
    15. this->procEnumerate(this->enumerator->devicesAvailable());
    16. }
    17.  
    18. MainWindow::~MainWindow()
    19. {
    20. delete ui;
    21. }
    22.  
    23.  
    24.  
    25.  
    26. //Slots
    27. void MainWindow::procEnumerate(const QStringList &l)
    28. {
    29. // Fill ports box.
    30. ui->comboBox_Port->clear();
    31. ui->comboBox_Port->addItems(l);
    32. }
    To copy to clipboard, switch view to plain text mode 

    I think there is an fault with a QList, but I can't find my fault.

    M
    Greeting
    Philipp

    P.s. I forgot the .pro file:
    Qt Code:
    1. QT += core gui
    2.  
    3. TARGET = Autorino_GUI_0_1_Beta
    4. TEMPLATE = app
    5.  
    6. include(qserialdeviceenumerator/qserialdeviceenumerator.pri)
    7. include(qserialdevice/qserialdevice.pri)
    8.  
    9.  
    10. SOURCES += main.cpp\
    11. mainwindow.cpp
    12.  
    13. HEADERS += mainwindow.h
    14.  
    15. FORMS += mainwindow.ui
    16.  
    17. win32 {
    18. LIBS += -lsetupapi -luuid -ladvapi32
    19. }
    20. unix:!macx {
    21. LIBS += -ludev
    22. }
    To copy to clipboard, switch view to plain text mode 


    Added after 1 23 minutes:


    Sorry for doublepost, I tryed to safe this->enumerator->serialDevicesAvailable() in a QStringList, but there is also the same error.
    Qt Code:
    1. //connect(this->enumerator,SIGNAL(hasChanged(QStringList)),this,SLOT(procEnumerate(QStringList)));
    2. //this->procEnumerate(this->enumerator->devicesAvailable());
    3. QStringList qsl = this->enumerator->devicesAvailable();
    To copy to clipboard, switch view to plain text mode 

    Greetings
    Philipp
    Last edited by mischter-x; 25th October 2011 at 13:47.

  6. #6
    Join Date
    Jan 2009
    Location
    Russia
    Posts
    309
    Thanks
    2
    Thanked 43 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: SerialProgramming qextserialport or QSerialDevice?

    In constructor MainWindow
    try remove:
    Qt Code:
    1. ...
    2. //Enumerator
    3. if(!this->enumerator)
    4. ...
    To copy to clipboard, switch view to plain text mode 

  7. #7
    Join Date
    Oct 2011
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: SerialProgramming qextserialport or QSerialDevice?

    Hello,

    this prt is working now.
    But I have a new problem now, with the function "this->serial->isOpen();"

    This is my code:
    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3.  
    4.  
    5. MainWindow::MainWindow(QWidget *parent) :
    6. QMainWindow(parent),
    7. ui(new Ui::MainWindow)
    8. {
    9. ui->setupUi(this);
    10.  
    11. initEnumerator();
    12. initSerial();
    13. initButtons();
    14. }
    15.  
    16. MainWindow::~MainWindow()
    17. {
    18. delete ui;
    19. }
    20.  
    21.  
    22. void MainWindow::initEnumerator()
    23. {
    24. this->enumerator = SerialDeviceEnumerator::instance();
    25. connect(this->enumerator,SIGNAL(hasChanged(QStringList)),this,SLOT(procEnumerate(QStringList)));
    26. this->procEnumerate(this->enumerator->devicesAvailable());
    27. }
    28.  
    29. void MainWindow::initSerial()
    30. {
    31. ui->plainTextEdit_ComMessage->setVisible(false);
    32. if (this->serial)
    33. return;
    34. this->serial = new AbstractSerial(this);
    35. connect(this->serial, SIGNAL(signalStatus(QString,QDateTime)), this, SLOT(procSerialMessages(QString,QDateTime)));
    36. connect(this->serial, SIGNAL(readyRead()), this, SLOT(procSerialDataReceive()));
    37.  
    38. // Enable emmiting signal signalStatus
    39. this->serial->enableEmitStatus(true);
    40.  
    41. ui->plainTextEdit_ComMessage->setVisible(false);
    42. }
    43.  
    44. void MainWindow::initButtons()
    45. {
    46. connect(ui->pushButton_connect,SIGNAL(clicked()),this,SLOT(procPushButtonConnect()));
    47. }
    48.  
    49.  
    50. //Slots
    51. void MainWindow::procEnumerate(const QStringList &l)
    52. {
    53. // Fill ports box.
    54. ui->comboBox_Port->clear();
    55. ui->comboBox_Port->addItems(l);
    56. }
    57.  
    58. void MainWindow::procSerialMessages(const QString &msg, QDateTime dt)
    59. {
    60. QString s = dt.time().toString() + " > " + msg;
    61. ui->plainTextEdit_ComMessage->appendPlainText(s);
    62. }
    63.  
    64. void MainWindow::procSerialDataReceive()
    65. {
    66. if (this->serial && this->serial->isOpen()) {
    67.  
    68. }
    69. }
    70.  
    71. void MainWindow::procPushButtonConnect()
    72. {
    73. if(this->serial)
    74. {
    75. bool result = this->serial->isOpen();
    76. if(result)
    77. {
    78. this->serial->close();
    79. ui->plainTextEdit_ComMessage->setVisible(true);
    80. ui->plainTextEdit_ComMessage->setEnabled(true);
    81. ui->pushButton_connect->setText("Connect");
    82. }
    83. else
    84. {
    85. this->serial->setDeviceName(ui->comboBox_Port->currentText());
    86. result = this->serial->open(QIODevice::ReadWrite);
    87. ui->plainTextEdit_ComMessage->setVisible(false);
    88. ui->plainTextEdit_ComMessage->setEnabled(false);
    89. ui->pushButton_connect->setText("Disconnect");
    90. }
    91. }
    92. }
    To copy to clipboard, switch view to plain text mode 

    The Debugger points on this line "bool result = this->serial->isOpen();"
    When I choose a Port, and click the button, I get this error message:

    The process was stop, after getting a Signal from the OS.
    Name of Signal: SIGSEGV
    Meaning: Segmentation fault

    Greetings
    Philipp

  8. #8
    Join Date
    Jan 2009
    Location
    Russia
    Posts
    309
    Thanks
    2
    Thanked 43 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: SerialProgramming qextserialport or QSerialDevice?

    This time you do that the same error as before.
    You have to study C + +, so do not do such a banal and stupid mistakes.
    These errors are not due to QSerialDevice.

    PS:
    I give you a hint: Always reset (try equal zero) pointers before using them!
    ie in your case, in order not to change all the code, you simply set equal to zero pointers to the port and the enumerator in constructors.
    Qt Code:
    1. MainWindow::MainWindow(QWidget *parent) :
    2. QMainWindow(parent),
    3. ui(new Ui::MainWindow),
    4. enumerator(0), serial(0)
    5. {
    6. ....
    7. ....
    8. }
    To copy to clipboard, switch view to plain text mode 

    And take a closer look examples - there's all there.
    Last edited by kuzulis; 28th October 2011 at 06:26.

Similar Threads

  1. QSerialDevice on Symbian
    By hubbobubbo in forum Qt Programming
    Replies: 2
    Last Post: 2nd October 2011, 19:00
  2. QSerialDevice v 0.2.0 released
    By kuzulis in forum Qt Programming
    Replies: 23
    Last Post: 18th September 2010, 23:30
  3. QSerialDevice Problem
    By waynew in forum Qt Programming
    Replies: 8
    Last Post: 21st January 2010, 14:31
  4. QSerialDevice
    By clinisbut in forum Qt Programming
    Replies: 2
    Last Post: 23rd October 2009, 13:30
  5. new library QSerialDevice
    By kuzulis in forum Qt Programming
    Replies: 2
    Last Post: 13th July 2009, 05:42

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.