Results 1 to 15 of 15

Thread: Adding QtSerialPort as a library -

  1. #1
    Join Date
    Jun 2012
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Adding QtSerialPort as a library -

    Hello!
    Thank you for having this newbie forum

    I am trying to add a library/add-on to my project in QT Creator 2.4.1, QtSerialPort.
    Actually, I have also tried QSerialDevice (QT 4 based) and QExtSerialPort, but haven't had any luck with either... Decided to try full out with QtSerialPort since it's a QT supported ad-on and is still updated.

    I don't really know how many errors I have produced trying to do this, so I don't know which to post here. I was kinda hoping someone could clear a couple things up for me before I start posting code and error messages?

    I finally got rid of many error by using MinGW instead of visual studio for compiling (?!). On the QSerialPort page it gives a description for making and adding the DLLs, but this one time I managed to compile it I didn't have no QT 5 folder where it could be output, as stated. But it says to support QT 4? Arrghh, I'm just so frustrated with this. Been sitting here all day and don't even know what questions to ask.

    Can I follow the steps in the link (QtSerialPort) for installing/using this library, and to what extend? I appreciate your answers very much....

    Thanks,
    Henrik

    edit: have calmed down a bit and will no try to do this from scratch while documenting.

    1.Starting at http://qt-project.org/wiki/QtSerialPort I download the source code at "Getting the source code: for users" by clicking the "this" link. I extract the contents of the .tar.gz to C:\Qt in a folder called qtplayground-qtserialport (same as tarball).

    2. I skip the part about building qt5 from source, jumping straight to the "Building" section (building the library). I open the serialport.pro in Qt Creator, then this pops up:
    Attachment 7912
    I don't do any changes in this window and click "finish". Before doing anything I go in the project settings and changing "Qt version" from "Qt 4.8.0 for Desktop - MSVC 2010 (Qt SDK)" to "Qt 4.8.0 for Desktop - MinGW (Qt SDK)".

    3. I then press the "build" button (hammer?), and get 336 warnings saying the same thing:
    c:\Qt\serialport-build-desktop-Qt_4_8_0_for_Desktop_-_MinGW__Qt_SDK__Debug\.qmake.cache:1: warning: Unmatched quotes are deprecated.
    It points to line 1 and 2 in .qmake.cache which consists of two lines:
    Qt Code:
    1. "SERIALPORT_PROJECT_ROOT = C:/Qt/qtplayground-qtserialport"
    2. "SERIALPORT_BUILD_ROOT = C:/Qt/serialport-build-desktop-Qt_4_8_0_for_Desktop_-_MinGW__Qt_SDK__Debug"
    To copy to clipboard, switch view to plain text mode 

    4. I then press the build-button again, having done nothing since getting the 336 warnings, and it builds just fine. Pressing the play/run button gives this in the output dialog:
    Starting C:\Qt\serialport-build-desktop-Qt_4_8_0_for_Desktop_-_MinGW__Qt_SDK__Debug\examples\enumerator\debug\en umerator.exe...
    The program has unexpectedly finished.
    C:\Qt\serialport-build-desktop-Qt_4_8_0_for_Desktop_-_MinGW__Qt_SDK__Debug\examples\enumerator\debug\en umerator.exe exited with code -1073741515
    5. Guide now says
    After building the module, there will be two library files (Release and Debug builds, respectively) in the Qt5 qtbase binary directory:
    but I have no such folder. I have also searched my computer for occurrences of these files, with no luck hehe. Where do I go from here?
    Attached Images Attached Images

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,709
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Adding QtSerialPort as a library

    It is my recommendation, that you first understand the following:
    1. What is a library - and what is the difference between a static and dynamic libs.
    2. How a lib is built, what linking means and what is needed for linking to succeed.

    Once you know the above, I guess most of the problems you face now will be clear to you - or at least, you will know where your problem is and you can ask the correct questions

    I'd suggest you take any online tutorial that explains these topics, and follow it, until you understand it.
    I finally got rid of many error by using MinGW instead of visual studio for compiling (?!).
    Read this:
    http://www.mingw.org/wiki/MixingCompilers
    It basically boils down to:
    If you are building everything your self (your libs and your application) - then you can build it with any compiler you like, but build all of them with the same compiler.
    If you use a ready built libs from a third party, you have to know with which compiler they are built with, and you you should build your application with the same compiler/tool chain.

    (Take a look at the download page of Qt, and you will see Qt builds for various compilers)

    Also:
    You should distinguish between compile errors - and link errors, and from what you have written, its not clear if your problems are linking or compiling.

    I then press the build-button again, having done nothing since getting the 336 warnings, and it builds just fine. Pressing the play/run button gives this in the output dialog:
    Look in the detailed build output, and paste here the first few errors you got.
    Last edited by high_flyer; 29th June 2012 at 17:40.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

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

    Default Re: Adding QtSerialPort as a library -

    2 HSPalm

    3. I then press the "build" button (hammer?), and get 336 warnings saying the same thing:
    c:\Qt\serialport-build-desktop-Qt_4_8_0_for_Desktop_-_MinGW__Qt_SDK__Debug\.qmake.cache:1: warning: Unmatched quotes are deprecated.
    This is normal, just ignore these warnings.

    but I have no such folder. I have also searched my computer for occurrences of these files, with no luck hehe. Where do I go from here?
    In theory, after building the library, you must install it by typing:
    $make install (if you use MinGW compiler)
    or
    $nmake install (if yuo use VS compiler)
    But in reality it until does not work (incomplete), so to install the library, do the following:

    !!!ONLY FOR Qt4.x!!!

    1. Build library any way (or through QtCreator, or from the console) using serialport.pro as release and debug.
    2. Copy folder /QtAddOnSerialPort (with all content) from library build directory to the Qt4 installation headers folder /include.
    3. Copy file "serialport.prf" from source library folder /src/qt4support/ to the Qt4 installation folder /mkspecs/features/
    4. Copy all builded libraries (as release ans as debug) SerialPort1.dll, SerialPortd1.dll, SerialPort1.lib (or *.a), SerialPortd1.lib (or *.a)
    to the Qt4 installation library folder /lib

    Now you can create a custom project that link library as follows:

    Your *.pro file:
    ...
    CONFIG += serialport
    ...
    Your *.cpp file, for example:
    Qt Code:
    1. #include <QCoreApplication>
    2.  
    3. #include <QtAddOnSerialPort/serialportinfo.h>
    4. // and/or
    5. #include <QtAddOnSerialPort/serialport.h>
    6.  
    7. #include <QDebug>
    8.  
    9. QT_USE_NAMESPACE_SERIALPORT
    10.  
    11. int main(int argc, char *argv[])
    12. {
    13. QCoreApplication a(argc, argv);
    14.  
    15. QList<SerialPortInfo> list = SerialPortInfo::availablePorts();
    16.  
    17. foreach (const SerialPortInfo &info, list) {
    18. QString s = info.portName();
    19. qDebug() << s;
    20. }
    21.  
    22. return a.exec();
    23. }
    To copy to clipboard, switch view to plain text mode 

    Enjoy....

  4. #4
    Join Date
    Jun 2012
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Adding QtSerialPort as a library -

    I AM SO SORRY, I thought this thread died a sudden death and I was discouraged to start a new one. Now that I've got my motivation back for re-posting I see all these wonderful answer which I will try out ASAP. Thanks guys!

  5. #5
    Join Date
    Jun 2012
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Adding QtSerialPort as a library -

    YOU ARE MY HEROES

    Thanks to both for enlightening me, I know understand better libraries and linking, and got help where I was stuck after that.

    edit: there's a typo in there...

  6. #6
    Join Date
    Oct 2012
    Location
    Jakarta
    Posts
    3
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Adding QtSerialPort as a library -

    Quote Originally Posted by kuzulis View Post
    2. Copy folder /QtAddOnSerialPort (with all content) from library build directory to the Qt4 installation headers folder /include.
    I have build the library through QtCreator 2.6
    I couldn't find /QtAddOnSerialPort in the library build directory.

    Where is it? Help me, please.

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

    Default Re: Adding QtSerialPort as a library -

    Please read Wiki

  8. #8
    Join Date
    Mar 2010
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Adding QtSerialPort as a library -

    I have to agree ilham, there is no folder /QtAddOnSerialPort to copy to the Qt 4.8 installation after compilation.

    The wiki doesn't address this.

    I can get everything to compile and include correctly, but without the QT_USE_NAMESPACE_SERIALPORT I can't use this library.

    Trying to incorporate this onto an ARM processor running linux, but did not have similar troubles using this library in Windows.

  9. #9
    Join Date
    Oct 2010
    Posts
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Adding QtSerialPort as a library -

    Quote Originally Posted by radix07 View Post
    I have to agree ilham, there is no folder /QtAddOnSerialPort to copy to the Qt 4.8 installation after compilation.
    It's QtSerialPort now

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

    Default Re: Adding QtSerialPort as a library -

    Yes, now made a lot of changes before stabilizing and public in Qt 5.1.

    So, just follow what is written in the Wiki, but not too close, because everything can change.

  11. #11
    Join Date
    Apr 2013
    Posts
    1
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Adding QtSerialPort as a library -

    I too am having problems with QtAddOnSerialPort. I'm trying to compile qSerialTerm, and am getting an error "mainwindow.h:26:42: fatal error: QtAddOnSerialPort/serialport.h: No such file or directory". And similarly, cannot find a QtAddOnSerialPort tree, or any mention of it, in the qtserialport code. It (qtserialport) seemed to make ok, though. I'm trying to build qSerialTerm so I can use it with the Bluetooth project I have going, so have been side-tracked a little by this.

    The qSerialTerm Wiki, which I've been following to build it, hasn't helped here so I thought I'd google around for some people who look like they know what they're doing

    UPDATE: I changed the files in qSerialTerm to use headers in the /usr/include/QtSerialPort instead if looking for them in QtAddOnSerialPort. That fixed the issue with qserialport.h and qserialportinfo.h, but now the build needs serialportwidget.h, which does not appear anywhere.
    Last edited by emueyes; 26th April 2013 at 07:57. Reason: further developments

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

    Default Re: Adding QtSerialPort as a library -

    QtSerialPort API changed and was more or less stabilized since was this theme is written.

    The freshest and actual invormation look in WIKI: http://qt-project.org/wiki/QtSerialPort

    Now QtAddOnSerialPort isn't present, and also namespace is now QT_USE_NAMESPACE. Look examples to library in /examples in more detail.

  13. #13
    Join Date
    Nov 2013
    Posts
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Adding QtSerialPort as a library -

    Hi guys,

    I'm developing on an Arm board, and I have to use a RS485 interface. I'm trying to use QtSerialPort: I added libQtSerialPort.so to my qt/lib folder on the board, but I still have problem on running my test on it.

    Compilation for both target and host runs well, and I also can run my simple test on the host linux pc. As I try to run in debug mode on the board, I get a "Could not load shared library symbols for 14 libraries, e.g. /usr/local/qt/lib/libQtSerialPort.so.1", even if this file exists in /usr/local/qt/lib.

    my .pro file is

    //////////////////////////////////////////////////////////////////////////////////////////
    QT += core

    QT -= gui

    TARGET = QtRs485Test
    target.files = QtRs485Test
    target.path = /disk

    INSTALLS += target
    CONFIG += console
    CONFIG += serialport
    CONFIG -= app_bundle

    TEMPLATE = app


    SOURCES += main.cpp
    ////////////////////////////////////////////////////////////

    and my .cpp file is

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

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

    foreach (const QSerialPortInfo &info, QSerialPortInfo::availablePorts()) {
    qDebug() << "Name :" << info.portName();
    qDebug() << "Description :" << info.description();
    qDebug() << "Manufacturer:" << info.manufacturer();

    QSerialPort serialPort;
    serialPort.setPort(info);
    if(serialPort.open(QIODevice::ReadWrite)){
    QString s = "hello from " + info.portName();
    serialPort.write(s.toUtf8());
    serialPort.close();
    }
    }

    return a.exec();
    }

    Thank you in advance

    P

  14. #14
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,543
    Thanks
    13
    Thanked 1,577 Times in 1,506 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Adding QtSerialPort as a library -

    Is that file a symbolic link to another that does not exist?
    What does:
    Qt Code:
    1. ldd ./yourexecutable
    To copy to clipboard, switch view to plain text mode 
    tell you on the target machine?

  15. #15
    Join Date
    Jun 2014
    Location
    Whidbey Island, WA, USA
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Adding QtSerialPort as a library -

    Thank you! I had gotten as far as installing the headers and libraries, but the example .pro files have a step to include serialport.prf from $$QTSERIALPORT_PROJECT_ROOT/src/serialport/qt4support/serialport.prf. $$QTSERIALPORT_PROJECT_ROOT is an empty string on my machine.

    Copying serialport.prf to /mkspecs/features was the missing piece for me. And use CONFIG += serialport rather than QT += serialport. Using Qt 4.8.6 here, and I have QT += widgets, but must use CONFIG += serialport.

    Thanks again!

Similar Threads

  1. cannot build qtserialport
    By banlinhtienphong in forum Qt Programming
    Replies: 1
    Last Post: 16th December 2011, 05:56
  2. Adding glew library
    By Cucus in forum Newbie
    Replies: 3
    Last Post: 20th June 2011, 22:44
  3. Adding library in another project
    By Anshuman in forum Qt Programming
    Replies: 1
    Last Post: 26th April 2011, 16:13
  4. Adding an external Library
    By afflictedd2 in forum Qt Programming
    Replies: 1
    Last Post: 13th December 2008, 05:51

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.