[Solved] Adding QtSerialPort to 4.6.3



  • Hi

    I am trying to add the QtSerialPort to my Qt 4.6.3.
    I have copied all the sources downloaded into a subfolder "QtSerialPort" into my project folder.
    I've added to project.pro:
    @CONFIG += serialport
    INCLUDEPATH += ./QtSerialPort/include/QtSerialPort
    include(QtSerialPort/src/serialport/qt4support/install-helper.pri)@

    Building on windows now returns (excerpt):
    @14:40:47: Starte "c:\qtsdk\desktop\qt\4.6.3\bin\qmake.exe" L:\target\src\sd\aixsolve\qtgui\src\qtgui.pro -r -spec win32-g++ "CONFIG+=release"
    Ein Unterverzeichnis oder eine Datei mit dem Namen "\include\QtSerialPort" existiert bereits.
    Ein Unterverzeichnis oder eine Datei mit dem Namen "\include\QtSerialPort" existiert bereits.
    Ein Unterverzeichnis oder eine Datei mit dem Namen "\include\QtSerialPort" existiert bereits.
    14:40:49: Der Prozess "c:\qtsdk\desktop\qt\4.6.3\bin\qmake.exe" wurde normal beendet.@

    and building on linux returns (excerpt):
    @mkdir: kann Verzeichnis „/include“ nicht anlegen: Keine Berechtigung
    sh: cannot create /include/QtSerialPort/QSerialPort: Directory nonexistent
    sh: cannot create /include/QtSerialPort/QSerialPortInfo: Directory nonexistent
    QtSerialPort/src/serialport/qt4support/src/qlockfile.cpp:42:23: fatal error: qlockfile.h: No such file or directory
    compilation terminated.@

    Can anybody help me with this?
    What do I need to do to have QtSerialPort with 4.6.3?

    Thanks a lot!



  • At first, do you read "WIKI":https://qt-project.org/wiki/QtSerialPort?

    Briefly:

    1. Try to compile QtSerialPort separately
    2. If there are errors of compilation, to correct them and to try to rebuild again and again.
    3. Try to install of compiled QtSerialPort into your Qt 4.6.3.
    4. Create an empty Qt project and to write to *.pro file:
      @
      CONFIG += serialport
      @
      and try to compile (to check of successfully linking of QtSerialPort with your empty project).
    5. If there are errors then try to check existence of *.so libraries, the *.prf and the *.h files in your Qt 4.6.3.
    6. If no files available, try to repeat from item 1 again. Or try to copy/paste manually desired files into your Qt 4.6.3 place.
    7. If all fine, then make item 4 for your project.

    That will do.

    Upd: For me doesn't excite as you earlier included the QextSerialPort, since the QtSerialPort has the own laws, and has nothing in common with QextSerialPort. Therefore simply don't try to make analogy. Therefore if you have not enough experience in Qt and in programming, then please do all items how I talk. :)



  • I read the wiki over and over. The explanations are not very detailed.
    I'll try again with your instructions and post back.



  • OK, I am now trying to simply add it to my local Qt installation and build it under windows. Let's move it to Linux later.

    • I copied to "C:\QtSDK\Desktop\Qt\4.6.3\src\qt-qtserialport"
    • I opened serialport.pro
    • Did Build settings
    • Replaced QElapsedTimer with QTime
    • changed include path in qserialportinfo_win.cpp #include "C:\QtSDK\mingw\include\ddk\cfgmgr32.h"
    • Changed include path in qserialport_win.cpp to #include "qt4support/include/QtCore/qwineventnotifier.h"
      and now getting

    @mingw32-make.exe[1]: Leaving directory `C:/QtSDK/Desktop/Qt/4.6.3/src/qt-qtserialport/src/serialport-build-desktop-Qt_4_6_3_for_Desktop_-_MinGW_Release'
    ..\serialport\qserialportinfo_win.cpp: In static member function 'static QList<QSerialPortInfo> QSerialPortInfo::availablePorts()':
    ..\serialport\qserialportinfo_win.cpp:258: error: 'find_if' is not a member of 'std'
    ..\serialport\qserialportinfo_win.cpp:307: error: 'find_if' is not a member of 'std'@



  • Added #include <algorithm> .... and moving further



  • I think I am missing this step because the libraries are built but not installed:

    • add a new make “Build Step” and write to the “Make arguments” the install target

    ... I am not really sure how to do this ?!?



  • ... found it:

    • Switch to Projects Mode: press Ctrl+5.
    • On Build Settings tab under Build Steps click on Add Build Step.
    • Choose Make from the menu.
    • Write install into Make arguments: text input box.

    .. libraries are installed in local 4.6.3 on windows. :)
    ... moving forward ...



  • Including into a new empty project does not work, returning:
    @release/main.o:main.cpp:(.text+0x66): undefined reference to _imp___ZN15QSerialPortInfo14availablePortsEv' release/main.o:main.cpp:(.text+0xf9): undefined reference to_imp___ZNK15QSerialPortInfo8portNameEv'
    release/main.o:main.cpp:(.text+0x23b): undefined reference to _imp___ZNK15QSerialPortInfo11descriptionEv' release/main.o:main.cpp:(.text+0x374): undefined reference to_imp___ZNK15QSerialPortInfo12manufacturerEv'
    release/main.o:main.cpp:(.text+0x4ab): undefined reference to _imp___ZN11QSerialPortC1EP7QObject' release/main.o:main.cpp:(.text+0x4be): undefined reference to_imp___ZN11QSerialPort7setPortERK15QSerialPortInfo'
    release/main.o:main.cpp:(.text+0x4d5): undefined reference to _imp___ZN11QSerialPort4openE6QFlagsIN9QIODevice12OpenModeFlagEE' release/main.o:main.cpp:(.text+0x4e2): undefined reference to_imp___ZN11QSerialPort5closeEv'
    release/main.o:main.cpp:(.text+0x4eb): undefined reference to _imp___ZN11QSerialPortD1Ev' release/main.o:main.cpp:(.text+0x94a): undefined reference to_imp___ZN11QSerialPortD1Ev'
    release/main.o:main.cpp:(.text$_ZN5QListI15QSerialPortInfoE4freeEPN9QListData4DataE[QList<QSerialPortInfo>::free(QListData::Data*)]+0x36): undefined reference to _imp___ZN15QSerialPortInfoD1Ev' release/main.o:main.cpp:(.text$_ZN5QListI15QSerialPortInfoE13detach_helperEv[QList<QSerialPortInfo>::detach_helper()]+0x68): undefined reference toimp___ZN15QSerialPortInfoC1ERKS'
    release/main.o:main.cpp:(.text$_ZN5QListI15QSerialPortInfoE13detach_helperEv[QList<QSerialPortInfo>::detach_helper()]+0xb6): undefined reference to `_imp___ZN15QSerialPortInfoD1Ev'
    @

    It installed .dll to /bin, .h to /include/QtSerialPort, .a, lib.dll and .prl to /lib. So far, this seems ok to me but it still returns the errors above.

    Any idea?



  • Found it. If its done like in the wiki with adding
    @CONFIG += serialport@

    to the pro, it does not work.
    I had to manually copy the prf from the sources and add:

    @include(C:\QtSDK\Desktop\Qt\4.6.3\lib\serialport.prf)@

    to the pro file (for what ever this file is for ?!?)
    Finally, it runs under windows ... now I'll try to port it to my eLinux environment .. which will be trickier, I assume.



  • The serialport.prf should be in \mkspecs\features\ in your Qt place. Then CONFIG += serialport should be work correctly.



  • Perfect! Thanks a lot.
    Now .. moving to Linux ... I'll keep this thread updated



  • Needed some changes to the sources. However, one line of code still bugs me:

    @const qint64 age = QFileInfo(fileName).lastModified().msecsTo(QDateTime::currentDateTime());@

    msecsTo is not available in QDateTime in 4.6.3.
    Any idea?



  • You can do not use QLockFile.. Just exclude this module/code from compilation (e.g. comments out some places and so on).



  • Thanks. Decided to replace
    @const qint64 age = QFileInfo(fileName).lastModified().msecsTo(QDateTime::currentDateTime());
    return staleLockTime > 0 && age > staleLockTime;
    @
    with
    @return staleLockTime > 0 && (QDateTime::currentDateTime() > QFileInfo(fileName).lastModified().addMSecs(staleLockTime));@

    It works! :)
    Just compiled for my eLinux and used the basics from the wiki reading out port names. Going to replace qextserialport with QtSerialPort now and hope it helpes in solving my communication issue.

    Thanks for your support and patience.



  • [quote author="McLion" date="1404925315"]Found it. If its done like in the wiki with adding
    @CONFIG += serialport@

    to the pro, it does not work.
    I had to manually copy the prf from the sources and add:

    @include(C:\QtSDK\Desktop\Qt\4.6.3\lib\serialport.prf)@

    to the pro file (for what ever this file is for ?!?)
    Finally, it runs under windows ... now I'll try to port it to my eLinux environment .. which will be trickier, I assume.
    [/quote]

    Did the same, althought serialport.prf is in mkspec/features directory and I've added CONFIG += serialport in *.pro file. Works as intended



  • [quote author="McLion" date="1404925315"]Found it. If its done like in the wiki with adding
    @CONFIG += serialport@

    to the pro, it does not work.
    I had to manually copy the prf from the sources and add:

    @include(C:\QtSDK\Desktop\Qt\4.6.3\lib\serialport.prf)@

    to the pro file (for what ever this file is for ?!?)
    Finally, it runs under windows ... now I'll try to port it to my eLinux environment .. which will be trickier, I assume.
    [/quote]

    Did the same, althought serialport.prf is in mkspec/features directory and I've added CONFIG += serialport in *.pro file. Works as intended


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.