PDA

View Full Version : Implementation in header, Qt forms, double compilation



zzz9
28th November 2012, 12:35
I have stuck on the following problem. I think it is mostly related to general programming issues.
I have a class with implementation in header file. I include it in a .dll (where it is supposed to be) and .exe. I suppose that the binary code for this class will be in the .dll file and .exe file, am I right?

Then imagine that there is a basic Qt form in a dll with exports flag. Generally, one have to include "ui_Form1.h" into an interface header file of the form's class, like this:


#include "ui_Form1.h"

class DllFileExport Form1 : public QWidget
{
...
Ui::Form1 ui;
}

When one uses this header in one of main project (.exe) files it means that the same code for Ui::Form1 class that has implementation in its header is compiled twice, in .dll and in .exe. That means that unnecessary (just rubbish) code will appear in .exe. It will not be used in .exe but this is not restricted as it is a basic non-private class of global scope.

The idea of this approach was to store dialogs and custom widgets with forms in another module which could be replaced by the same module with bug fixes.

What is the main approach of avoiding unnecessary double compilation of ui form class in .exe and .dll files?

I suppose I should make a private class as a main dialog's class and a public class that inherits private class. With this approach header for ui from class will be hided within .dll module files that won't be included into main project which means no double compilation of the same code. Am I right?

Another approach is to make uic for Qt 4 generate interface and implementation for ui form files in two different files: .h and .cpp. I haven't found any uic keys to make this. Does anyone know about any?

zzz9
3rd December 2012, 08:41
I have solved the problem using UI form layout class as a pointer to forward declared class.