Instructables

Control your arduino from your PC with the Qt Gui

For my first instructable I will show you how to use Qt to make graphic interfaces for your arduino (or any rs232 device)

So if you want to create your own graphic interfaces, you want to control stuff just by clicking buttons from your screen, this instructable is for you.

To do this we will use Qt (say : "cute") from nokia.
Of course Qt is not the only program that can make graphical interface.
But these are the advantages of Qt :
- It is free and open source software (distributed under the terms of the GNU Lesser General Public License)
- It is C/C++, so widely used.
- You can compile your program on a lot of platform (Windows, Linux, ...)
- The possibilities are infinite (you probably have many applications coded on Qt : Skype, Google Earth, VLC, ...

I only provide basic things to start.
Here we just see how to install Qt, the serial port library and write your first program.
The program will control the brightness of a led.

I admit that you already know know C/C++. If it is not the case, there are plenty of  course on the web. If your are a french speaker (like me), I suggest the course from www.siteduzero.fr which is very good to start from zero.



 
Remove these adsRemove these ads by Signing Up

Step 1: Intallation of Qt

Picture of Intallation of Qt

The first step of this instructable is to get and install Qt.

You can get Qt sdk from this wedsite : http://qt.nokia.com/products/

Once downloaded, follow the instruction to install it.

The first part is over. Fairly easy, isn't it?
The next part is a bit more tricky.


snoop9117 months ago

Are there any Qt IDEs (commercial or open source) that have a m$ visual studio feel to it?

I was thinking of doing a simple GUI for an embedded application using Tcl/Tk but seems like there's not many resources available (ActiveState dropped Komodo GUI builder in 2007!)

Also any thoughts on GTK+, OpenBox, openFramework, wxWidgets, or any of the other popular GUI libraries http://en.wikipedia.org/wiki/List_of_platform-independent_GUI_libraries

jloibman1 year ago
OK, I just sad that I can't use your tutorial, it's so well explained..
I saw at code.google.com/p/qextserialport that there is support for Qt5 so I thought I could follow your tutorial..
Do you still use Qt 4.7.3? Is there any chance you got the qt SDK installer?
jloibman1 year ago
Hello. I tried to follow the steps but it didn't work on qt5.1. Do you know how do I do that? I even tried to download and install qt 4.7.3, but with no success.. Hope you can help me. So what I could manage to have on my PC is Qt 5.1.0 with Mingw. If you can get in touch with me by email I'll be so grateful too.. My email is jloibman@gmail.com
intructable (author)  jloibman1 year ago
The library does not seem to work on qt5.X. Instead you might use this new Qt add-on : http://qt-project.org/wiki/QtSerialPort , I have not tried but I think it has the same features that the qtserialport library.
tsun12 years ago
Hi,

I've been working on your examples theses days. Unfortunately, every time last build step, Qt showed up:
enumwidget.obj:-1: error: LNK2019: unresolved external symbol "public: __thiscall QextSerialPort::QextSerialPort(class QString const &,enum QextSerialBase::QueryMode)" ( ??0QextSerialPort@@QAE@ABVQString@@W4QueryMode@QextSerialBase@@@Z) referenced in function "public: void __thiscall Widget::init_port(void)" (?init_port@Widget@@QAEXXZ).

Any suggestions?

varuninnz2 years ago
Hey mate,

I went to my Qt SDK desktop. I had 4.7.4 & 4.8.1.
I followed both your instruction for both 4.7.4 & 4.8.1 just like you've showed them in the picture.
And it seemed to work exactly how its displayed on your cmd window.

Also instead I downloaded the beta file.
QextSerialPort_1_2_Beta2. But I believe the procedure is very similar.

Then the next, I did was open the project file from your portcomsender. After this I went inside the portcomsender.pro and changed the

INCLUDEPATH += C:/Qt/qextserialport-1.2win-alpha/
LIBS += C:\Qt\qextserialport-1.2win-alpha\build\libqextserialportd.a

to

INCLUDEPATH += C:/qt/qextserialport-1.2beta/
LIBS += C:\Qt\qextserialport-1.2beta\buildlib\buildlib.pro

I did this because I could not libqextserialportd.a or any .dll files.
Im really not sure what to do here. Should I just copy the ibqextserialportd.a & .dll files from the aplha to the buildlib of the beta folder?






intructable (author)  varuninnz2 years ago
Hi varuninnz
I am not sure that you should export the alpha files to the beta folder, this might be a bad idea.
I have not tried the beta yet so I don't know what you have to do. You should probably check what the developers expect you to do to run this new library. Usually you can easily find instructions in the downloaded files.

Tell me when you find a solution to your problem.

Cheers
jkrishna12 years ago
When i typed in this "F:\QtSDK\qextserialport-1.2win-alpha>f:\QtSDK\mingw\bin\mingw32-make.exe "

following error comes,
sbs -c winscw_udeb.mwccinc
sbs: error: tool 'MWLD' from config 'none' did not return version 'Version 3.2.*
' as required.
Command 'mwldsym2.exe -version' returned:
/bin/bash: mwldsym2.exe: command not found

Check your environment and configuration.

What went wrong?

1o_o72 years ago
Here is the latest qextserialport project. It is no longer at sourceforge.
http://code.google.com/p/qextserialport/
intructable (author)  1o_o72 years ago
Thanks,
I change the link.
mojocorp2 years ago
Hi,
There is a mistake in the code:

char *buf; //creation of a buffer
*buf = value;

buf point to random memory and changing the value may randomly crash.

char buf = (char)value;
port->write(&buf, 1); //send the buffer

or better

port->write(QByteArray(1, (char)value)); //send the buffer
intructable (author)  mojocorp2 years ago
It is correct,
Another solution is to allocate the pointer with a "new" :

char *buf;
buf = new char;

and then delete the pointer to avoid a memory overflow :

delete buf;

This is a mistake I often do because these problems are sometime solved during the compilation.

Thank you for your comment and fill free to correct me again.
Helm212 years ago
Some helpful hints...

1. In the QtCreator I had to change the 'build configuration' under "Projects" (on the left side) from Debug to Release

2. The two lines char *buf; *buf = value; caused a crash of my programm. The compiler did its job, but when I ran the prog und called the method "transmitCmd(int value)", it crashed. I thing the conversion from int to char isn't possible this way... I did it this way: char buf; buf=(int)value; port->write(&buf);

3. All included DLL-files have to be copied in the C:/WIndows folder