Qt GUI in Application module

Forum for software developers to discuss BCI2000 software development
Posts: 10
Joined: 23 Jun 2010, 09:36

Qt GUI in Application module

Post by gdimitri » 07 Apr 2011, 11:00

Hello Juergen,

I have some questions regarding the use of Qt (external to the one bundled in BCI2000) to create GUIs for my modules.
What I would like to do is create an Application module that shows me a Qt GUI created through the use of Qt designer and that links properly to the BCI2000 main loop so that input to the GUI can be passed to the rest of the modules.

My first question has to do with the setup of the CMakeLists.txt file for the module so that Qt will properly generate the moc_ files for the classes that call the Q_OBJECT macro and for the .ui file generated by the designer. You seem to be using the QT4_AUTOMOC together with the QT_WRAP_CPP and QT_WRAP_UI. I am just learning Qt but from the CMake docs I though that QT4_AUTOMOC negates the need to do QT_WRAP_* macros but is not so stable. Could you explain how do I need to write a CMakeLists.txt file for an Application module that passes the files to the BCI2000_ADD_APPLICATION_MODULE macro (which also calls QT4_AUTOMOC) so that I get proper generation of my moc_ files. I have tried to do this but failed. So now I create my moc files using Qt creator and then insert them in the BCI2000 project. Very unellegant and tiresome whenever changes happen (which is constantly).

The second question has to do with the different event loops that are created if I create an application module calling CoreModuleQt.Run() and then creating a Qt GUI calling a gui.exec() from inside the OnStartRun() of the Application module. These two event loops will not talk to each other and the GUI is useless (at least I think so). Do I have to make my own CoreModuleGUI (and override the ProcessGUIMessages and the GUIMessagesPending)? Could you give me some pointer as to how I need to set up my code so that the GUI's event loop and the BCI2000 core loop either are the same thing or talk to each other.

P.S. I have a Code::Blocks system in Windows 7 compilling with MinGW. I am using the latest V3.0 of BCI2000

Thank you very much


Posts: 1172
Joined: 12 Feb 2003, 11:06

Re: Qt GUI in Application module

Post by mellinger » 08 Apr 2011, 08:47

Hello George,

regarding your first question, using both QT4_AUTOMOC and QT_WRAP_CPP in the BCI2000_ADD_APPLICATION_MODULE macro makes makes some sense because the first covers header files included from cpp files which are not in the list of headers, and the second covers header files that are not included by any of the cpp files given to QT4_AUTOMOC. To cover all possible cases, you have to use both. However, all header files should be listed as such anyway, so QT_WRAP_CPP should suffice in principle. (Documentation for these macros is available in the FindQt4.cmake file inside your CMake installation.)

Please note that QT4_AUTOMOC does not replace QT_WRAP_UI. You will need to call QT_WRAP_UI on your .ui files separately, and add the generated files to the list of files specified in the BCI2000_ADD_APPLICATION_MODULE call:

Code: Select all

QT4_WRAP_UI( GENERATED_UI mydialog.ui )
Regarding the event loop question, you don't need to call a Qt exec() function. CoreModuleQT does Qt event dispatching already, so just create a dialog and call its show() method to display it. Exec() is for modal dialogs only, and cannot be used within a BCI2000 application module, because it would block BCI2000 operation.

Hope this helps,

Posts: 34
Joined: 17 Nov 2009, 15:15

Re: Qt GUI in Application module

Post by jhill » 09 Apr 2011, 14:20

Eh up, Dr D. Just to throw in a quick observation: before you think too hard about building anything too elaborate into an actual BCI2000 Application module, you might consider whether the rather simpler and more flexible model of an AppConnector application might also do what you want. You can build your GUI application however you want, if so. --jez


Who is online

Users browsing this forum: No registered users and 2 guests