PDA

View Full Version : Heelppp please !



berzeck
7th July 2007, 15:43
This is my problem, i have created custom widgets which i put them on a library ( PulzarLib)
when i use the widgets as members of a class in my program everything is ok.. but if i INHERIT my custom widget ( from the library PulzarLib) my program crashes

PD: Sorry my bad english !

jpn
7th July 2007, 18:26
Please, try to use more descriptive thread titles. Could you provide an example that reproduces the problem?

berzeck
10th July 2007, 05:21
Please, try to use more descriptive thread titles. Could you provide an example that reproduces the problem?

Thanks for answering, here is my problem : i have made an application that is composed of libraries, the application itself and a set of modules implemented as plugins:

This is the structure of my applcation :

- PulzarApp ( the application itself )
- PulzarLib ( Core libraried)
- PulzarMod (Modules, implemented as plugins)
- PulzarQtPluguins ( Pluguins for Qt designer, custom widgets )
- PulzarRps ( Reports, implemented as plugins )
- Pulzar Rpt ( Report engine, library )
- PulzarXml ( The reports definitions )

So far so good, my application runs flawless in linux, but when i compilie in windows i had some trouble :

First Problem : My application crashes once compiled, i start to trace the problem and noticed the one of the classes in PulzarApp inherits from a class of PulzarLib , so just for test, i removed that dependency and reimplemented the PulzarApp class without any inheritance from PulzarLib and made instances of PulzarLib classes to keep the functionality ... that worked. But the "solution" came when i compiled PulzarLib as a static lib... i dont know why, and its far better to have that library as shared ( dll )

Second problem :
I have a class MainWindow ( which is my applications Main Window itself ) in PulzarApp which inherits MainWindowGui from PulzarLib, i need to have a pointer to the MainWindow so components can communicate with others , i tried to implement this using a static member of MainWindowGui :

MainWindowGui.h :

{
QOBJECT
......
private :
static MainWindowGui* self;
.....
}

MainWindowGui.cpp

MainWindowGui* MainWindowGui::self = 0;

MainWindowGui::MainWindowGui( ...)
{
MainWindowGui::self = this;
}

but when i call this pointer later it always retunr 0, crashing my application ( again in linux this wasnt a problem )

thank you very much for your help

Eldritch
10th July 2007, 16:27
It's hard to offer more detailed help without more specific code, or a more detailed 'pseudo-code' description of your application.

I'm guessing, but it sounds like you've got some globals and / or static data that act as your fundamental data structures. This generally leads to odd problems such as what you're describing, because different compilers can generate the initialization code for globals and statics in slightly different ways. This is even more likely when you move from one platform to another. I've had this kind of problem happen to me before. The solution is to use explicit initialization / cleanup functions to guarantee that you know when objects are properly created / destroyed, and NOT rely on the behavior of a specific compiler.

For example, what is the first code that accesses MainWindowGui::self? If it's not the constructor of MainWindowGui, then MainWindowGui::self will be NULL.

When does your code create MainWindowGui? If you have a global variable that access MainWindowGui::self before you've called the MainWindowGui constructor explicitly, there's no way MainWindowGui::self can be properly initialized.

Also, I foresee that you may run into some fun problems using your library in other Qt programs. These problems stem from the requirement that there be only one QApplication. If your code always creates a QApplication, then you'll have some trouble if someone else has a program that creates a QApplication and then loads and uses your library. You can work around some of those problems by checking for an application instance and creating it if you need to.

Hope something in this helps! ;-)

berzeck
11th July 2007, 06:16
It's hard to offer more detailed help without more specific code, or a more detailed 'pseudo-code' description of your application.

I'm guessing, but it sounds like you've got some globals and / or static data that act as your fundamental data structures. This generally leads to odd problems such as what you're describing, because different compilers can generate the initialization code for globals and statics in slightly different ways. This is even more likely when you move from one platform to another. I've had this kind of problem happen to me before. The solution is to use explicit initialization / cleanup functions to guarantee that you know when objects are properly created / destroyed, and NOT rely on the behavior of a specific compiler.

For example, what is the first code that accesses MainWindowGui::self? If it's not the constructor of MainWindowGui, then MainWindowGui::self will be NULL.

When does your code create MainWindowGui? If you have a global variable that access MainWindowGui::self before you've called the MainWindowGui constructor explicitly, there's no way MainWindowGui::self can be properly initialized.

Also, I foresee that you may run into some fun problems using your library in other Qt programs. These problems stem from the requirement that there be only one QApplication. If your code always creates a QApplication, then you'll have some trouble if someone else has a program that creates a QApplication and then loads and uses your library. You can work around some of those problems by checking for an application instance and creating it if you need to.

Hope something in this helps! ;-)


Thank you very much for answering. I have solved my problems and you were right !
for any one interested :

Resolution Problem 1 : Symbols must be exported explicitly in Windows ( shitdows for now on ) when building a shared library. check this thread : http://www.qtcentre.org/forum/f-qt-programming-2/t-dll-application-6474.html

i havent sleep for 2 nights investigating this problem , first time i encounter a very technical problem to hate windows very veeery much :D

Resolution Problem 2 : i have fallen in the "static initialization order fiasco" trap. check this page : http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.15

thank you for answering again eldritch :)