Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt UI for existing C++ project

I have already written a C++ program and I would like to write a GUI for it. I realize Qt is a wonderful tool, however, Qt has it's own classes, which make me quite confused. eg: instead of String, Qt has a class named QString..

I am wondering if I can mix C++ code and Qt code in C++?

like image 240
Lily Avatar asked Aug 28 '09 21:08

Lily


2 Answers

Yes you can intermix Qt and STL very easily.

The GUI takes QStrings but will silently create these form std::string or char*, QStrings returned from Qt can be converted with toStdString() or toAscii().

Qt includes a set of collection classes but you don't have to use them.

Qt does a good job of looking like modern C++, there are a few 'extras' to handle the signal and slot event mechanism but these are more a complication to the build environment than to the code.

edit:thanks bill

like image 151
Martin Beckett Avatar answered Oct 01 '22 23:10

Martin Beckett


I wont recommend mixing std c++ code and Qt code together.

Let's say, your c++ code is the logic then the Qt code , should be just for GUI. Using a MVC/MVP patterns or likewise, separate your logic and UI.

Thus,it would be easier in the future to be able to run your code with/without using a UI.

like image 44
prog_guy Avatar answered Oct 01 '22 23:10

prog_guy