Results 1 to 9 of 9

Thread: Load Plugins on Windows

  1. #1
    Join Date
    Jun 2010
    Posts
    100
    Thanks
    13
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Load Plugins on Windows

    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
    Qt Code:
    1. #include <QtGui>
    2. #include <QtCore>
    3. #include <QApplication>
    4. #include <QMessageBox>
    5.  
    6. #include <iostream>
    7. using namespace std;
    8.  
    9. #include "C:\Dokumente und Einstellungen\itadmin\workspaceTest\LDMS\ILDMS.h"
    10.  
    11. int main(int argc, char *argv[])
    12. {
    13. QApplication a(argc, argv);
    14.  
    15. QPluginLoader loader("C:\esp\plugins\LDMS.dll");
    16.  
    17. QObject *plugin = loader.instance();
    18.  
    19. if(plugin){
    20. QMessageBox msgBox;
    21. msgBox.setText("Loaded");
    22. msgBox.exec();
    23. }else{
    24. QMessageBox msgBox;
    25. msgBox.setText("Not loaded");
    26. msgBox.exec();
    27. }
    28. return a.exec();
    29. }
    To copy to clipboard, switch view to plain text mode 

    pro file
    Qt Code:
    1. TEMPLATE = app
    2. TARGET = GuiLoaderPlugin
    3.  
    4. QT += core \
    5. gui
    6.  
    7. HEADERS +=
    8. SOURCES += main.cpp
    9. FORMS +=
    10. RESOURCES +=
    To copy to clipboard, switch view to plain text mode 


    Plugin .cpp

    Qt Code:
    1. #include "ldms.h"
    2.  
    3. void LDMS::init(){
    4. ui.setupUi(this);
    5. }
    To copy to clipboard, switch view to plain text mode 

    .h

    Qt Code:
    1. #ifndef LDMS_H
    2. #define LDMS_H
    3.  
    4. #include <QtGui/QWidget>
    5. #include "ui_ldms.h"
    6.  
    7. #include "ILDMS.h"
    8.  
    9. class LDMS : public QWidget,
    10. public ILDMS
    11. {
    12. Q_OBJECT
    13. Q_INTERFACES(ILDMS)
    14.  
    15. public:
    16. void init();
    17.  
    18. private:
    19. Ui::LDMSClass ui;
    20. };
    21.  
    22. #endif // LDMS_H
    To copy to clipboard, switch view to plain text mode 

    interface

    Qt Code:
    1. #ifndef ILDMS_H_
    2. #define ILDMS_H_
    3.  
    4. #include <QtCore>
    5.  
    6. class ILDMS {
    7. public:
    8.  
    9. virtual void init() = 0;
    10.  
    11. };
    12.  
    13. Q_DECLARE_INTERFACE(ILDMS,
    14. "esp.ibex/1.0")
    15.  
    16. #endif /* ILDMS_H_ */
    To copy to clipboard, switch view to plain text mode 

    pro file

    Qt Code:
    1. TEMPLATE = lib
    2. CONFIG += plugin
    3. DESTDIR = C:\esp\plugins
    4. TARGET = LDMS
    5. QT += core \
    6. gui
    7. HEADERS += ILDMS.h \
    8. ldms.h
    9. SOURCES += ldms.cpp
    10. FORMS += ldms.ui
    11. RESOURCES +=
    To copy to clipboard, switch view to plain text mode 

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

    Thanks in advance!

  2. #2
    Join Date
    Dec 2009
    Posts
    128
    Thanks
    7
    Thanked 14 Times in 14 Posts
    Platforms
    Unix/X11 Windows

    Default Re: Load Plugins on Windows

    My first guess would be line 15 of your 1st code snippet : you have to escape backslashes in the address string

  3. #3
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Load Plugins on Windows

    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.

  4. #4
    Join Date
    Jun 2010
    Posts
    100
    Thanks
    13
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Load Plugins on Windows

    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.

  5. #5
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Load Plugins on Windows

    Quote Originally Posted by ruben.rodrigues View Post
    I changed the slashes to backslashes but it still doesn't work...
    As stated, theres no need to change the slashes to back slashes.

    Quote Originally Posted by ruben.rodrigues View Post
    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?

  6. #6
    Join Date
    Jun 2010
    Posts
    100
    Thanks
    13
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Load Plugins on Windows

    Quote Originally Posted by squidge View Post
    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

  7. #7
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Load Plugins on Windows

    Where is the Q_EXPORT_PLUGIN2 macro?

  8. The following user says thank you to Lykurg for this useful post:

    ruben.rodrigues (13th May 2011)

  9. #8
    Join Date
    Jun 2010
    Posts
    100
    Thanks
    13
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Load Plugins on Windows

    Quote Originally Posted by Lykurg View Post
    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(/)

  10. #9
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Load Plugins on Windows

    Quote Originally Posted by ruben.rodrigues View Post
    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?

Similar Threads

  1. QPixmap cannot load data on Windows Mobile 6.1
    By _Stefan in forum Qt for Embedded and Mobile
    Replies: 3
    Last Post: 31st August 2010, 11:57
  2. Why can Qt Creator use QPluginLoader to load plugins?
    By MorrisLiang in forum Qt Programming
    Replies: 4
    Last Post: 25th April 2010, 16:00
  3. How to load DLL(C/C++) in Qt on Windows?
    By josecarlosmissias in forum Newbie
    Replies: 1
    Last Post: 20th November 2009, 15:52
  4. Gifs don't load in QTextEdit under windows
    By balazsbela in forum Newbie
    Replies: 4
    Last Post: 26th August 2008, 22:28
  5. Application Plugins in Windows [XP]
    By dcurtis in forum Installation and Deployment
    Replies: 10
    Last Post: 9th February 2007, 03:01

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.