PDA

View Full Version : Best way porting linux software written in C Gtk Ecplipse to C++ Qt Qt Creator?



Grumpy
5th February 2016, 11:24
Hi,
I need to give new life to an old huge and complex software written in C and Gtk+2.0 library on ide Eclipse. The software must be installed on a PC with a custom linux distribution. Software is composed of two projects that works with the logic server-client. I thought that the best choice would be to port the projects in C++, Qt library on Qt Crerator even if I'm quite newbie in C++ and Qt
I have a lot of work to do because the whole gui was written without a designer and I want to use the Creator Designer to recreate it, very much code will be translated in c++ also to improve the readability, much code are difficult to understand ecc...the problem is to choose the best way to start! I tryed to use the import function of Creator to import the project from Eclipse to try to reuse all the possible old code and minimize the new code but QT Creator only work as editor...so it is not useful. I'm starting to create a new project in Creator for the GUi, as first step, and to write all code from the begin looking the old code as a trace but the huge code to port make me look for another easier and specially faster way to do this job.
Can anyone suggest me how to proceed to speed this work?
Thanks

anda_skoa
5th February 2016, 11:48
It should be possible to import a makefile base project into QtCreator, but also to use Eclipse for the Qt version.

One migration technique when coming from a different UI technologie is to
- first remove the old library from the build system, in your case GTK
- then #ifdef everything that does not compile anymore
- then work from main() down, porting each #ifdef'ed part as you encounter it

Rewriting from scratch has the risk that you could miss things that the old applications was able to do or make mistakes when implementing processing logic.
Especially since this is, as you write, a complex application.

Cheers,
_

If this is something that a company needs to have done, I would even suggest to at least get an offer from one of the Qt service providers who have many years of experience with these kind of migrations.
Some of them even do such estimates for free.

Grumpy
5th February 2016, 16:01
Thanks for the tips, I was inspired!
During my experiments i was able to create a project in Qt Creator with both Qt and Gtk+ library included. The next job is to port step by step the old source files trying to build the entire old projet in Qt Creator. Then I'll replace the gkt code with Qt trying to use the Qt designer.
If this procedure fails I'll do what you suggested

d_stranz
5th February 2016, 16:25
During my experiments i was able to create a project in Qt Creator with both Qt and Gtk+ library included.

Right. Qt Creator is just an IDE, like Eclipse or Visual Studio. You can develop any kind of C++ project in Qt Creator, even though it is especially tuned for working on Qt projects. You mainly need to get your project set up in the kit so it includes all of the right include paths and libraries.

So you are on the right track. If you like Qt Creator and are more familiar with it than Eclipse, then use it. The Qt Designer integration will certainly be useful when you start replacing GUI components.

Grumpy
4th March 2016, 11:41
Hi...I have some bad news!
Now I have the old project C with gtk that works correctly in a Qt Creator project but...if a try to use Qt (For example any #include of Qt to add a Qt form or function) i receive a lot of build error. Adding the only row #include <QtCore> I receive:
In file included from ../../../Qt5.5.1/5.5/gcc/include/QtCore/qobjectdefs.h:41:0,
from ../../../Qt5.5.1/5.5/gcc/include/QtCore/qobject.h:40,
from ../../../Qt5.5.1/5.5/gcc/include/QtCore/qabstractanimation.h:37,
from ../../../Qt5.5.1/5.5/gcc/include/QtCore/QtCore:4,
from ../vgp02/main.c:36:
../../../Qt5.5.1/5.5/gcc/include/QtCore/qnamespace.h:47:1: error: unknown type name 'QMetaObject'
const QMetaObject *qt_getQtMetaObject() Q_DECL_NOEXCEPT; // defined in qobject.h (which can't be included here)
^
../../../Qt5.5.1/5.5/gcc/include/QtCore/qnamespace.h:58:1: error: unknown type name 'namespace'
namespace
^
../../../Qt5.5.1/5.5/gcc/include/QtCore/qnamespace.h:62:4: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
Qt {
^
../../../Qt5.5.1/5.5/gcc/include/QtCore/qnamespace.h:1715:33: error: expected ')' before ':' token
Q_DECLARE_OPERATORS_FOR_FLAGS(Qt::MouseButtons)
^
../../../Qt5.5.1/5.5/gcc/include/QtCore/qnamespace.h:1740:1: warning: data definition has no type or storage class [enabled by default]
class Q_CORE_EXPORT QInternal {
^
../../../Qt5.5.1/5.5/gcc/include/QtCore/qnamespace.h:1740:1: warning: type defaults to 'int' in declaration of 'class' [enabled by default]
../../../Qt5.5.1/5.5/gcc/include/QtCore/qnamespace.h:1740:21: error: expected ',' or ';' before 'QInternal'
class Q_CORE_EXPORT QInternal {
^
In file included from ../../../Qt5.5.1/5.5/gcc/include/QtCore/qobjectdefs.h:43:0,
from ../../../Qt5.5.1/5.5/gcc/include/QtCore/qobject.h:40,
from ../../../Qt5.5.1/5.5/gcc/include/QtCore/qabstractanimation.h:37,
from ../../../Qt5.5.1/5.5/gcc/include/QtCore/QtCore:4,
from ../vgp02/main.c:36:
../../../Qt5.5.1/5.5/gcc/include/QtCore/qobjectdefs_impl.h:50:1: error: unknown type name 'namespace'
namespace QtPrivate {
^
../../../Qt5.5.1/5.5/gcc/include/QtCore/qobjectdefs_impl.h:50:21: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
namespace QtPrivate {
^
In file included from ../../../Qt5.5.1/5.5/gcc/include/QtCore/qobject.h:40:0,
from ../../../Qt5.5.1/5.5/gcc/include/QtCore/qabstractanimation.h:37,
from ../../../Qt5.5.1/5.5/gcc/include/QtCore/QtCore:4,
from ../vgp02/main.c:36:
../../../Qt5.5.1/5.5/gcc/include/QtCore/qobjectdefs.h:48:1: error: unknown type name 'class'
class QByteArray;
^
../../../Qt5.5.1/5.5/gcc/include/QtCore/qobjectdefs.h:50:1: error: unknown type name 'QArrayData'
typedef QArrayData QByteArrayData;
^
../../../Qt5.5.1/5.5/gcc/include/QtCore/qobjectdefs.h:52:1: error: unknown type name 'class'
class QString;
^
../../../Qt5.5.1/5.5/gcc/include/QtCore/qobjectdefs.h:131:10: error: expected '=', ',', ';', 'asm' or '__attribute__' before '<' token
template <typename T>
^
../../../Qt5.5.1/5.5/gcc/include/QtCore/qobjectdefs.h:134:10: error: expected '=', ',', ';', 'asm' or '__attribute__' before '<' token
template <typename T1, typename T2>
^
../../../Qt5.5.1/5.5/gcc/include/QtCore/qobjectdefs.h:247:1: error: unknown type name 'class'
...
...
...
... and more and more

If I only add to the project a Qt designer form class the building is ok, the editor found the Qt library correctly but really... I can't use it.
So...how can I use Qt in my project????

anda_skoa
4th March 2016, 14:12
Hi...I have some bad news!
Now I have the old project C with gtk that works correctly in a Qt Creator project but...if a try to use Qt (For example any #include of Qt to add a Qt form or function) i receive a lot of build error. Adding the only row #include <QtCore> I receive:

In general, adding a module header is not a good idea unless you are making a quick&dirty prototype.

Did you include that before or after project specific includes?
What does the compiler call look like?

Cheers,
_

Grumpy
4th March 2016, 14:39
hummmm, I did some test and i figured out the problem is to try using Qt in my C files. In a Qt project with one only C files (classic Hello world) if include Qt it returns error, if a rename the file in C++ it is all ok.
So, the ways I thought are:
1_convert all my file C in C++...I hope no
2_convert the main.c in main.cpp, solve the problem of conversion and call the other C file putting extern when the header is called....hoping the extern works.
3_create a simple new main file in c++ then call all the other files with extern as above
Best way? Other ways?


In general, adding a module header is not a good idea unless you are making a quick&dirty prototype.


Sorry, I don't get what you say? How should I specified the Qt library to use?

anda_skoa
4th March 2016, 18:26
hummmm, I did some test and i figured out the problem is to try using Qt in my C files. In a Qt project with one only C files (classic Hello world) if include Qt it returns error, if a rename the file in C++ it is all ok.

So the problem was that the file was being compiled by the C compiler which then chocked on the C++ stuff.



So, the ways I thought are:
1_convert all my file C in C++...I hope no

Only necessary if you use C++ in these files.



2_convert the main.c in main.cpp, solve the problem of conversion and call the other C file putting extern when the header is called....hoping the extern works.

Don't see why not, this is how C libraries get called after all :)



3_create a simple new main file in c++ then call all the other files with extern as above

I guess that also works.



Sorry, I don't get what you say? How should I specified the Qt library to use?
Well, an include doesn't have anything to do with a library being used, but if you meant how to use Qt classes, then the best way is to include the headers for those you actually need.

A module header requires the compiler to read and parse all headers of the module, increasing the build time for no gain.

Cheers,
_