Hello,
the problem is "QWidget: Must construct a QApplication before a QPaintDevice".
Please read below
on win32/vs2008 and linux32/g++4.4,
I build static libraries and an executable/binary that links against those static libraries.
I have a "plot" static library( plot.lib or libplot.a ) that includes a main.cpp translation unit.
This defines a namespace-scope variable
namespace NS1 { namespace NS2 {
int argc_for_qapp=0;
}
}
namespace NS1 { namespace NS2 {
int argc_for_qapp=0;
QApplication app(argc_for_qapp, 0);
}
}
To copy to clipboard, switch view to plain text mode
so the symbol NS1::NS2::app is the variable.
in another translation unit in "plot", there is
namespace NS1 { namespace NS2 {
void f()
{
...
app.exec();
}
}}
namespace NS1 { namespace NS2 {
extern QApplication app;
void f()
{
...
app.exec();
}
}}
To copy to clipboard, switch view to plain text mode
There is the application's main.cpp that calls the function f().
As I understand there is no guarantee of the initialization of globals between translation units, but there is a guarantee that all of them are initialized before the main function.
In Debug there is no problem, in Release there is the problem:
"QWidget: Must construct a QApplication before a QPaintDevice"
In Release vs2008, I made sure the linker options for the executable that includes, in Linker/Optimization/References => "Keep Unreferenced Data"
Linker/Optimization/Enable COMDAT Folding => "Do Not Remove Redundant COMDATs "
so the reference to NS1::NS2::app that is in another translation unit is not removed.
Again in debug mode, this works fine.
in release/linux32/g++4.4, same error.
rds,
Bookmarks