PDA

View Full Version : Load Plugins on Windows



ruben.rodrigues
12th May 2011, 18:14
Hi all!

I am used to do plugins on ubuntu but now I need to do some on windows and it's just not working.

this code works prefecty on ubuntu: (of couse the destination folder is different)

Loader Class main.cpp

#include <QtGui>
#include <QtCore>
#include <QApplication>
#include <QMessageBox>

#include <iostream>
using namespace std;

#include "C:\Dokumente und Einstellungen\itadmin\workspaceTest\LDMS\ILDMS.h"

int main(int argc, char *argv[])
{
QApplication a(argc, argv);

QPluginLoader loader("C:\esp\plugins\LDMS.dll");

QObject *plugin = loader.instance();

if(plugin){
QMessageBox msgBox;
msgBox.setText("Loaded");
msgBox.exec();
}else{
QMessageBox msgBox;
msgBox.setText("Not loaded");
msgBox.exec();
}
return a.exec();
}

pro file

TEMPLATE = app
TARGET = GuiLoaderPlugin

QT += core \
gui

HEADERS +=
SOURCES += main.cpp
FORMS +=
RESOURCES +=


Plugin .cpp


#include "ldms.h"

void LDMS::init(){
ui.setupUi(this);
}


.h


#ifndef LDMS_H
#define LDMS_H

#include <QtGui/QWidget>
#include "ui_ldms.h"

#include "ILDMS.h"

class LDMS : public QWidget,
public ILDMS
{
Q_OBJECT
Q_INTERFACES(ILDMS)

public:
void init();

private:
Ui::LDMSClass ui;
};

#endif // LDMS_H


interface


#ifndef ILDMS_H_
#define ILDMS_H_

#include <QtCore>

class ILDMS {
public:

virtual void init() = 0;

};

Q_DECLARE_INTERFACE(ILDMS,
"esp.ibex/1.0")

#endif /* ILDMS_H_ */


pro file


TEMPLATE = lib
CONFIG += plugin
DESTDIR = C:\esp\plugins
TARGET = LDMS
QT += core \
gui
HEADERS += ILDMS.h \
ldms.h
SOURCES += ldms.cpp
FORMS += ldms.ui
RESOURCES +=


this works perfectly with ubuntu but on windows I just keep getting "Not loaded" messages.

Thanks in advance!

totem
12th May 2011, 18:19
My first guess would be line 15 of your 1st code snippet : you have to escape backslashes in the address string

squidge
12th May 2011, 18:36
You don't even need back slashes, forward slashes will work fine. Keep back slashes for the purpose they were made for - escaping characters.

Even Windows itself supports forward slashes in paths (and has done for years), but lots of applications require backslashes because authors assume they are the standard.

ruben.rodrigues
12th May 2011, 20:05
I changed the slashes to backslashes but it still doesn't work... :(

I also tried with the libLDMS.a and without the .a but nothing.

squidge
12th May 2011, 22:57
I changed the slashes to backslashes but it still doesn't work... :(As stated, theres no need to change the slashes to back slashes.


I also tried with the libLDMS.a and without the .a but nothing.QPluginLoader doesn't support .a files, only DLL files.

What is the error that is reported?

ruben.rodrigues
13th May 2011, 07:41
As stated, theres no need to change the slashes to back slashes.

QPluginLoader doesn't support .a files, only DLL files.

What is the error that is reported?

There is no error message. The if(plugin) return false when it shouldnt. I also tried to put the dll and the exe in the same folder but it also didn't work

Lykurg
13th May 2011, 07:54
Where is the Q_EXPORT_PLUGIN2 macro?

ruben.rodrigues
13th May 2011, 08:27
Where is the Q_EXPORT_PLUGIN2 macro?

I am going to kill my self right after I post this...can't fkin believe that I forgot the macro specially when I have it on my code under ubuntu...

Thanks a lot Lykurg!

By the way...I had also to change the backslashes(\) to fowardslashes(/)

squidge
13th May 2011, 08:39
There is no error message. The if(plugin) return false when it shouldnt. I also tried to put the dll and the exe in the same folder but it also didn't work

I know you fixed this now, but when it returns false, typically QPluginLoader::errorString () is set to some message to explain why. Are you saying this was an empty string?