PDA

View Full Version : DLL problem im confuse..



triperzonak
25th February 2009, 11:14
:confused:

first can you guys check if what i did is right?

in my .h



#ifdef MYDLL
#define MYDLLAPI Q_DECL_EXPORT
#else
#define MYDLLAPI
#endif

#include <QDialog>

class MYDLLAPI MyClass : public QDialog
{
Q_OBJECT
public:
MyClass(QWidget * parent = 0, Qt::WFlags f = 0 );
public slots:
void showMsg();
}

/*i dont have a UI*/


in my .pro


/*i added*/
CONFIG += dll release
TEMPLATE = lib
DEFINES = MYDLL


this will create a myclass.a and myclass.dll (im using windows mingw)

it will be use by the other application
here's what I've done

in my app .pro i added


LIBS += "<path to my lib>\libmyclass.a"
INCLUDEPATH = "<path to includes>"

in my app code


#include "myclass.h" //from the include of dll

/*some includes*/

int main (int argc, char * argv [])
{
QApplication app( argc, argv );
QLibrary *loadmylibrary = new QLibrary("myclass"); //my dll
loadmylibrary->setLoadHints(QLibrary::ResolveAllSymbolsHint);
loadmylibrary->load();
if (loadmylibrary->isLoaded() == false)
qDebug()<<"error not loaded";

else
{
qDebug()<<"loaded";
MyClass *mycls; //from my dll

mycls->showMsg();
}

app.connect( &app, SIGNAL( lastWindowClosed() ), &app, SLOT( quit() ) );
return app.exec();
}


my applications show:


loaded

QWidget: Must construct a QApplication before a QPaintDevice


then the messagebox will not show from the dll.. how can i solve this? :confused:

jpn
25th February 2009, 15:12
Why are you linking to and loading the same library again at runtime?

triperzonak
26th February 2009, 01:36
thanks bro..

i remove the QLibrary and rebuild my apps and dll.. it is now working.

is there a problem if i build a dll from static build of qt?.. :)