TEMPLATE = libTARGET = DEPENDPATH += .INCLUDEPATH += .# InputHEADERS += dynlib.hSOURCES += dynlib.cppCONFIG +=dll
#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 = appTARGET = DEPENDPATH += .INCLUDEPATH += .# InputSOURCES += main.cpp
#include <QtGui>// ----------------------------------------------------------------------int main(int argc, char** argv){ QApplication app(argc, argv); QLabel lbl("this is the example text"); QLibrary lib("DLL"); typedef QString (*Fct) (const QString&); Fct fct = (Fct)(lib.resolve("oddUpper")); if (fct) { lbl.setText(fct(lbl.text())); } lbl.show(); return app.exec();}
TEMPLATE = libTARGET = DEPENDPATH += .INCLUDEPATH += .CONFOG +=dll# InputHEADERS += dynlib.hSOURCES += dynlib.cpp
#ifdef Q_OS_WIN #define LIB_EXPORT __declspec(dllexport)#else #define LIB_EXPORT#endif#include <QString>LIB_EXPORT 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;}
extern "C" MY_EXPORT int avg(int a, int b){ return (a + b) / 2;}
#ifdef Q_WS_WIN#define MY_EXPORT __declspec(dllexport)#else#define MY_EXPORT#endif