QextSerialPort is a nice library for serial port communication. It is based on C++ cross-platform Qt framework and must have in the toolkit of DSP/embedded software developer.
I’ve spent several hours trying to compile QextSerialPort for Visual Studio 2010 + Qt 4.7.1. Here is my recipe to success.
We assume that Qt is installed in C:\Qt\4.7.1
(see How To Compile Qt 4.7 with Visual Studio 2010 for instructions).
We will build QextSerialPort in C:\Qt\qextserialport
.
- Download and install TortoiseHG (if you don’t have it already).
- Download vcconvert.bat and copy it to
C:\Qt
.
This script automates Visual Studio 2010 project files generation from QextSerialPort sources. - Start Visual Studio 2010 Command Prompt
- Run following commands in it:
cd c:\Qt
hg clone https://qextserialport.googlecode.com/hg/ qextserialport
vcconvert.bat
- Open
C:\Qt\qextserialport\qextserialport.sln
in Visual Studio 2010. - Select qextserialportd project in Solution Explorer
Alt+F7:
General -> Target Name:
changeqextserialportd1
toqextserialportd
Linker -> General -> Output file:
changebuild\qextserialportd1.dll
tobuild\qextserialportd.dll
- Choose Release configuration and repeat previous step.
- Compile
qextserialportd
project in Debug and Release modes.
Now we have ready-to-use DLLs (along with drop-in export lib files) here:
C:\Qt\qextserialport\src\build\
qextserialport.dll
qextserialport.exp
qextserialport.lib
qextserialportd.dll
qextserialportd.exp
qextserialportd.ilk
qextserialportd.lib
qextserialportd.pdb
It is good idea to copy all these files to C:\Qt\4.7.1\lib\
and DLLs only to C:\Qt\4.7.1\bin\
.
You can download already compiled QextSerialPort Binaries.
Remarks
*Homepage of the QextSerialPort is http://code.google.com/p/qextserialport/. Do not use sourceforge page – it is outdated!
12 Comments
How would you then include the library in your Visual Studio 2010 Qt application?
By adding export library
qextserialport.lib
to a project and including header file to your sources.If this sounds gibberish, google for: adding dll to Visual C++ project or similar keywords. This is just basic knowledge.
Thanks for your help. I’m new to the Visual Studio IDE. When you say add exportt library qextserialport.lib to the project do you mean take these steps:
Right Click project -> Click Properties ->Click Configuration Properties -> Click Linker ->Click Input -> and then add qextserialport.lib to the ‘Additional Dependencies’ list?
Thanks for your time.
Here are steps on how to integrate QextSerialPort in Visual Studio 2010. I assume it locates in
C:\Qt\qextserialport
1. Add
C:\Qt\qextserialport\src\
toConfiguration Properties -> C/C++ -> Additional Include Directories
.2. Add
C:\Qt\qextserialport\src\build\
toConfiguration Properties -> Linker -> Additional Library Directories
3. Add
qextserialport.lib
toConfiguration Properties -> Linker -> Input -> Additional Dependencies
4. Add
#include <qextserialport.h>
to your source file.5. Compile Project. Copy
qextserialport.dll
fromC:\Qt\qextserialport\src\build\
to the folder where compiled EXE file is. Nowqextserialport.dll
will be loaded automatically when program starts, so distribute it along with your application.These steps are valid for both
Release
andDebug
build configurations.Although it is better to use
qextserialportd.lib
andqextserialportd.dll
forDebug
builds.Hope this helps.
Thanks I’m getting closer but still get an error. App can’t start up. Doing something really simple (cpp file looks like below):
#include “openserialport.h”
#include “ui_openserialport.h”
#include “qextserialenumerator.h”
OpenSerialPort::OpenSerialPort(QWidget *parent) :
QDialog(parent),
ui(new Ui::OpenSerialPort)
{
ui->setupUi(this);
QList ports = QextSerialEnumerator::getPorts();
}
OpenSerialPort::~OpenSerialPort()
{
delete ui;
}
When I run the app it can’t run (ugly error ‘Application was unable to start correctly’). If I take out the line : QList ports = QextSerialEnumerator::getPorts(); The app runs fine.
I doubled check the steps you wrote out and it looks correct. Ever see this error?
Try to copy DLL to the solution folder (where *.sln file resides)
Pavel, thanks for your help on this. I went back to square one and rebuilt Qt 4.7.3 as per your instructions in another thread, and then followed the steps as you describe in this thread and no more error at application start up.
Oh, great, glad to help.
Thank you so much for this information. You saved me a ton of time getting this to build in MSVC++ 2008!
This thread was very helpful saving me from building in mingw. Thanks a lot.
BTW, Are there any updates on this thread pertaining to msvc2010? Hoping for msvc2010 support.
Thanks and more power.
I think procedure for msvc2012 will be similar.
There are no big differences in compiling Qt itself by msvc2012 – so I guess QextSerialPort would be similar.
Hey!
Did you already try to compile the qextserialport for Qt5.0.1? I tried to compile it for VisualStudio2010 + Qt5.0.1 but there is always an error in VisualStudio when I want to compile for debug:
fatal error LNK1123 error while converting into COFF. Data is invalid or damaged.
Do you maybe know what could be wrong?
Best regards,
Markus Eder