Answer the question
In order to leave comments, you need to log in
How to include your DLL in QT?
There is a compiled library in which there is one function:
dynlib.h:
#include <QString>
extern "C++" {
QString oddUpper(const QString& str);
}
#include "dynlib.h"
QString oddUpper(const QString& str)
{
QString strTemp;
for (int i = 0; i < str.length(); ++i) {
strTemp += (i % 2) ? str.at(i) : str.at(i).toUpper();
}
return strTemp;
}
TEMPLATE = lib
DESTDIR = ..
QT -= gui
SOURCES = dynlib.cpp
HEADERS = dynlib.h
TARGET = dynlib
#include <QtWidgets>
int main(int argc, char** argv)
{
QApplication app(argc, argv);
QLabel lbl("this is the example text");
QLibrary lib("dynlib");
typedef QString (*Fct) (const QString&);
Fct fct = (Fct)(lib.resolve("oddUpper"));
if (fct) {
lbl.setText(fct(lbl.text()));
}
else{
lbl.setText("DLL NOT FOUND!");
}
lbl.show();
return app.exec();
}
TEMPLATE = app
QT += widgets
DESTDIR = ..
SOURCES = main.cpp
TARGET = MyApplication
Answer the question
In order to leave comments, you need to log in
1. Instead of extern "C++" you need extern "C" , otherwise the name of your function will be spoofed, and it will be very difficult to find it by name.
2. Get Dependency Walker and check that your function is actually exporting correctly from the DLL.
3. So what exactly is the problem? What error are you getting?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question