Search code examples
c++swingqtuser-interfacegtkmm

Building a graphical user interface for an existing large C++ code


I'm currently developing on a tool with some existing large C++ code. I'm currently thinking about using a model-view-controller (MVC) design. The model should contain all the C++ code. The view is what the user sees and the controller is basically the glue between the model and the view.

The features that I'm looking for are:

  • Expandable design with MVC
  • Textual User Interface (TUI), terminal and Graphical User Interface (GUI) option
  • The GUI should load some textual files
  • The GUI should use some textual input of the user to run some algorithms and generate some output values
  • The GUI should eventually pop-up, save, display some graph with GNU plot for example.
  • The C++ code works great in Eclipse (libraries, includes, build options)
  • In time new algorithms will be added to the C++ code, this shouldn't become a big problem.

Now I found 3 solutions:

  • QT -> QT Creator nearly demands the usage of an IDE that makes it messy to go to from Eclipse despite the advantages of QT. QT also seems to demand a weird structure around the GUI, so i'm confused about how to make a controller. The eclipse plugin is currently dead, I cannot find it on the FTP of QT and Nokia.
  • GTKmm -> Comes from C and is sometimes a bit hard to understand why some things are required. I believe I can make this work in a MVC design.
  • Java Swing using a shared library (JNI) -> Makes use of Java and C++, which is a bit odd. Using JNI might cost some additional work on the existing C++ code.

I have some experience with Java Swing and nearly no experience with QT and GTKmm.

So what is the best solution for making a GUI when I already have an existing C++ code as an inexperienced UI developer?


Solution

  • Of your 3 options, I would definitely go with Qt.

    Basically for Qt to be a functional GUI, you need to start QApplication, show() some sort of widget and then start the event loop for the application (QApplication::exec()).

    http://qt-project.org/doc/qt-4.8/qapplication.html

    http://qt-project.org/doc/qt-4.8/qapplication.html#exec

    Qt is extremely flexible and well thought out, and has a strong following. And it has incredible documentation.

    To interact with your existing C++ data structures, just construct them as a member variable as one of the main widgets that you have for your GUI. Then when you want to access and display information on it, it is a piece of cake.

    http://qt-project.org/doc/qt-4.8/qwidget.html

    http://qt-project.org/doc/qt-4.8/qmainwindow.html

    Most of the GUI elements in Qt only act as the view, and there isn't any definitive Model and Controller setup. That is left to the developer. If you are displaying a database or a tree or a grid of items there is a model/view flow, but I don't think it applies to your application.

    Understanding and using SIGNALS and SLOTS is essential to making an interactive GUI in Qt, and is very painless.

    http://qt-project.org/doc/qt-4.8/signalsandslots.html

    http://qt-project.org/doc/qt-4.8/qobject.html#details

    Reading up on all the different kinds of QWidgets out there, you should be able to find each of the elements you listed in your question.

    Here are some you should look at:

    http://qt-project.org/doc/qt-4.8/qtextstream.html

    http://qt-project.org/doc/qt-4.8/qtextedit.html

    http://qt-project.org/doc/qt-4.8/qlineedit.html

    http://qt-project.org/doc/qt-4.8/qlabel.html

    And of course look through the tutorials and examples that come with Qt.

    How to use GNUPlot with Qt

    http://lists.trolltech.com/qt-interest/2002-12/thread00068-0.html

    Also, as a developer that has used both Qt Creator and Eclipse, I prefer Qt Creator, and porting a project to work in Qt Creator is very straight forward. If you want to change the build chain of Eclipse to use the Qt libraries and QMake, it is possible too.

    http://qt-project.org/doc/qt-4.8/qmake-project-files.html

    http://qt-project.org/doc/qt-4.8/qmake-project-files.html#declaring-other-libraries

    http://therning.org/magnus/archives/1023

    I hope that is helpful. Good luck.