how to use Qt dll in Win32 project
Hello !
I created a project Qt dll, It compiles and runs perfectly.
I get in the output files:
test.dll
test.lib
also have the following files:
test.h
test_global.h
Now, faced with the task, to connect the library to the project in C + + (without Qt!!!)
but in the files
test.h
test_global.h
there is a connection # include <Qt\qglobal.h>
And the project is not going to, and not linked.
Prompt how to create a header file that can connect the library to the project Win32 ?
Re: how to use Qt dll in Win32 project
You have to expose some interface that will not contain any Qt related things. Then make your Qt class inherit and implament that interface. Then you'll only deliver the base class header file, without any Qt related things.
Re: how to use Qt dll in Win32 project
Quote:
Originally Posted by
wysota
You have to expose some interface that will not contain any Qt related things. Then make your Qt class inherit and implament that interface. Then you'll only deliver the base class header file, without any Qt related things.
May be you can show some example ?
Re: how to use Qt dll in Win32 project
Quote:
Originally Posted by
Fastman
May be you can show some example ?
Let's see...
Code:
class SomeInterface {
public:
virtual ~SomeInterface(){}
virtual int method1() const = 0;
virtual std::string method2(int) = 0;
// etc.
};
class MyQtImplementation : public SomeInterface {
public:
MyQtImplementation(...){...}
int method1() const { qDebug() << "Qt here"; return 1; }
std
::string method2
(int num
) { return QString::number(num
).
toStdString();
}};
Re: how to use Qt dll in Win32 project
Code:
// H - Interface
class ISampleClass {
public:
virtual ~ISampleClass() {}
void DemoFunction1();
void DemoFunction2() = 0; // [OPTIONAL] Abstract function, so the complete class is abstract
};
// H - Implementation
class SampleClass
: public QObject,
public ISampleClass
{ Q_OBJECT
public:
virtual ~SampleClass() {}
void DemoFunction1();
void DemoFunction2();
};
// CPP - Implementation
}
void SampleClass::DemoFunction1() {
// Do Something
}
void SampleClass::DemoFunction2() {
// Do Something
}
Hope this helps
LG NoRulez
Re: how to use Qt dll in Win32 project
Re: how to use Qt dll in Win32 project
Hmmm... but i'am have some trouble:
Code:
error LNK2019: unresolved external symbol "public: void __thiscall ISampleClass::DemoFunction1(void)" (?DemoFunction1@ISampleClass@@QAEXXZ) referenced in function _wmain
Code:
#include "stdafx.h"
#include <string.h>
#include <iostream>
#include "../test/ISample.h"
#pragma comment(lib,"D:\\QT_PROJECT\\test\\debug\\test.lib")
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
ISampleClass a;
a.DemoFunction1();
return 0;
}
What wrong ???
Re: how to use Qt dll in Win32 project
do it this way..
Code:
// H - Interface
class ISampleClass {
public:
virtual ~ISampleClass() {}
static ISampleClass* getInstance();
virtual void DemoFunction1() = 0; //make everything pure virtual
virtual void DemoFunction2() = 0; // [OPTIONAL] Abstract function, so the complete class is abstract
private:
static ISampleClass *p;
};
// CPP - Implementation
ISampleClass* ISampleClass::p=0;
static ISampleClass* ISampleClass::getInstance();
{
if(!p)
p= new SampleClass;
return p;
}
// H - Implementation
class SampleClass
: public QObject,
public ISampleClass
{ Q_OBJECT
public:
virtual ~SampleClass() {}
void DemoFunction1();
void DemoFunction2();
};
// CPP - Implementation
}
void SampleClass::DemoFunction1() {
// Do Something
}
void SampleClass::DemoFunction2() {
// Do Something
}
//MAIN
int _tmain(int argc, _TCHAR* argv[])
{
ISampleClass* a= ISampleClass::getInstance();
a->DemoFunction1();
return 0;
}
Re: how to use Qt dll in Win32 project
Sorry, i'am stupid :) :o
Now everything works.
I realized QScritEngin in a DLL and is connected to an external win32 project.
Once again, thank you very much.