Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use Qt as C++ Library without using its UI framework

Tags:

c++

qt

mfc

Does it make sense to use Qt for increasing the productivity in an MFC app, without actually using the Qt user interface system?

I am currently looking or a good productivity library for my MFC based application, with useful container classes, string algorithmus, threading classes, I/O classes and so on. The Qt API is very nice in my opinion. However, since I don't want to switch my UI to Qt (just too much effort), I am wondering whether Qt can be used well in a MFC app without any Qt UI.

Thanks in advance for your opinions.

Fabian

like image 977
Fabian Avatar asked Dec 25 '09 22:12

Fabian


People also ask

Is Qt a library or framework?

Qt is a cross-platform application development framework for desktop, embedded and mobile. Supported Platforms include Linux, OS X, Windows, VxWorks, QNX, Android, iOS, BlackBerry, Sailfish OS and others. Qt is not a programming language on its own. It is a framework written in C++.

Can Qt be used with C?

Short answer: no. If you need a comprehensive GUI toolkit for C, you can use GTK+. To use Qt, you must have a C++ compiler. But it doesn't mean that your "application logic" can't be written in C, compiled with a C compiler and carefully linked to the C++ part (the GUI with Qt).

Is Qt good for GUI?

Qt for Python is one of the best GUI framework available for Python. We can build standard desktop GUI applications but the framework also comes with a lot of features such as data visualization or OpenGL support. The developer tools available are another powerful feature of the framework.

Is Qt a framework?

Qt is the complete software development framework. The Qt framework contains a comprehensive set of highly intuitive and modularized C++ library classes and is loaded with APIs to simplify your application development.


2 Answers

Qt is divided into several modules (QtGui being one of them). You can hand pick which modules are used by your application by linking only against the libraries you need.

I cannot answer whether Qt will be interopable with MFC. But at the very least, QString offers conversion to std::string and char*/wchar, which should help you quite a bit.

The Qt documentation provides an overview over the modules.

As daniel pointed out below, you have to be aware of the event loop. It is possible however to use the event loop without the GUI module. You can call processEvents on QCoreApplication to process all queued events and then return. There is one caveat with deferred deletions, but the documentation describes the workaround.

like image 163
shartte Avatar answered Sep 21 '22 05:09

shartte


There are some utility classes that you can use but there is a very important caveat. Qt depends very heavily on its event loop. The event loop is started by calling QApplication::exec(). Now many Qt classes depend on the signals and slots mechanism is Qt. Signals and slots are totally dependent on the event loop to function correctly.

This is totally true for the GUI modules but is also true of some of the other modules. One can expect every class derived from QObject to use signals and slots and will therefore be unusable without the event loop.

like image 30
doron Avatar answered Sep 21 '22 05:09

doron