Results 1 to 12 of 12

Thread: Plugins confusion

  1. #1
    Join Date
    Feb 2006
    Posts
    32
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Plugins confusion

    Does anyone know if it's possible to pass a pointer to the mainwindow of an application (that is, the application's specific subclass of QMainWindow) into a plugin then use the pointer to call methods in the MainWindow? For example, if I define a method in my MainWindow called drawImage(), can I call this from a plugin?

    I am getting really confused and have been trying to get my code to work for days now. Rather than go into detail about all the things I have tried, I thought I would ask the general question first, then get to the specifics based on the response (if any).

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Plugins confusion

    Yes, it is possible. Taken that your plugin is represented by an instance of some class:

    Qt Code:
    1. class SomeIFaceImpl : public QObject, SomeIFace {
    2. Q_OBJECT
    3. public:
    4. SomeIFaceImpl(){ m_mw = 0; }
    5. void storePointer(MyMainWindow *mw){ m_mw = mw; }
    6. void useStoredPointer(){ if(m_mw) m_mw->doSomething(); }
    7. private:
    8. MyMainWindow *m_mw;
    9. };
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Feb 2006
    Posts
    32
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Plugins confusion

    Quote Originally Posted by wysota
    Yes, it is possible.
    Excellent. Do you have any idea why my code doesn't work then? I can post some code showing how I have implemented this, but firstly let me explain the problem - it's quicker that way.

    I have a MainWindow and a Plugin which is passed the mainwindow pointer - much like your example. The Plugin can use the main window pointer to access data members in the mainwindow. However, if I try to call a function, that's where the problems occur!

    In Linux I get a symbol error:

    symbol lookup error: libGeMapMSUPlugin.so: undefined symbol:
    _ZN10MainWindow6canvasEv

    In Windows, the plugin won't even compile which is strange! I get the following link error (link errors in a library - whats going on?):

    Qt Code:
    1. > make
    2. mingw32-make -f Makefile.Release
    3. mingw32-make[1]: Entering directory `C:/Documents and Settings/pdrummond/Desktop/src/morph/GeMapMSUPlugin'
    4. g++ -c -O2 -O2 -Wall -frtti -fexceptions -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_NO_DEBUG -DQT_PLUGIN -DQT_QT3SUPPORT_LIB -DQT3_SUPPORT -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREA
    5. D_SUPPORT -I"C:/Qt/4.1.0/include/QtCore" -I"C:/Qt/4.1.0/include/QtGui" -I"C:/Qt/4.1.0/include/Qt3Support" -I"C:/Qt/4.1.0/include" -I"C:/Qt/4.1.0/include/ActiveQt" -I"release" -I"."
    6. -I"C:/Qt/4.1.0/mkspecs/win32-g++" -o release\MSUDevicePlugin.o MSUDevicePlugin.cpp
    7. g++ -mthreads -Wl,-enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -Wl,-s -Wl,-s -shared -Wl,--out-implib,release\libGeMapMSUPlugin.a -o "release\GeMa
    8. pMSUPlugin.dll" release\MSUDevicePlugin.o release\MSUDeviceIcon.o release\moc_MSUDevicePlugin.o -L"C:\Qt\4.1.0\lib" -lQt3Support4 -lQtGui4 -lQtCore4
    9. Creating library file: release\libGeMapMSUPlugin.a
    10. release\MSUDevicePlugin.o(.text+0x896):MSUDevicePlugin.cpp: undefined reference to `MainWindow::canvas()'
    11. collect2: ld returned 1 exit status
    12. mingw32-make[1]: *** [release\GeMapMSUPlugin.dll] Error 1
    13. mingw32-make[1]: Leaving directory `C:/Documents and Settings/pdrummond/Desktop/src/morph/GeMapMSUPlugin'
    14. mingw32-make: *** [release] Error 2
    To copy to clipboard, switch view to plain text mode 

    Something isn't quite right here! Any ideas?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Plugins confusion

    Does your project file state that the compilation is a plugin (I think you need both the "plugin" and "dll" options)?

    As for Linux, you need to add a switch to the main app to allow plugins to resolve its symbols within the application binary. The switch is "-rdynamic".

    You can add it to the project file like this:

    QMAKE_LFLAGS += -rdynamic

    Remember to rerun qmake afterwards.

  5. #5
    Join Date
    Feb 2006
    Posts
    32
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Plugins confusion

    Quote Originally Posted by wysota
    Does your project file state that the compilation is a plugin (I think you need both the "plugin" and "dll" options)?
    I will try the Linux switch tonight (I only have access to windows here at work).

    As far as windows goes, I had the "plugin" option defined but not "dll" - I added it, did a make clean, qmake, make and the compile error still occurs:

    Qt Code:
    1. > make
    2. mingw32-make -f Makefile.Release
    3. mingw32-make[1]: Entering directory `C:/Documents and Settings/pdrummond/Desktop/src/morph/GeMapMSUPlugin'
    4. g++ -c -O2 -O2 -Wall -frtti -fexceptions -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_NO_DEBUG -DQT_PLUGIN -DQT_QT3SUPPORT_LIB -DQT3_SUPPORT -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREA
    5. D_SUPPORT -I"C:/Qt/4.1.0/include/QtCore" -I"C:/Qt/4.1.0/include/QtGui" -I"C:/Qt/4.1.0/include/Qt3Support" -I"C:/Qt/4.1.0/include" -I"C:/Qt/4.1.0/include/ActiveQt" -I"release" -I"."
    6. -I"C:/Qt/4.1.0/mkspecs/win32-g++" -o release\MSUDevicePlugin.o MSUDevicePlugin.cpp
    7. g++ -c -O2 -O2 -Wall -frtti -fexceptions -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_NO_DEBUG -DQT_PLUGIN -DQT_QT3SUPPORT_LIB -DQT3_SUPPORT -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREA
    8. D_SUPPORT -I"C:/Qt/4.1.0/include/QtCore" -I"C:/Qt/4.1.0/include/QtGui" -I"C:/Qt/4.1.0/include/Qt3Support" -I"C:/Qt/4.1.0/include" -I"C:/Qt/4.1.0/include/ActiveQt" -I"release" -I"."
    9. -I"C:/Qt/4.1.0/mkspecs/win32-g++" -o release\MSUDeviceIcon.o MSUDeviceIcon.cpp
    10. C:\Qt\4.1.0\bin\moc.exe -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_NO_DEBUG -DQT_PLUGIN -DQT_QT3SUPPORT_LIB -DQT3_SUPPORT -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -I"C:/Q
    11. t/4.1.0/include/QtCore" -I"C:/Qt/4.1.0/include/QtGui" -I"C:/Qt/4.1.0/include/Qt3Support" -I"C:/Qt/4.1.0/include" -I"C:/Qt/4.1.0/include/ActiveQt" -I"release" -I"." -I"C:/Qt/4.1.0/m
    12. kspecs/win32-g++" -D__GNUC__ -DWIN32 MSUDevicePlugin.h -o release\moc_MSUDevicePlugin.cpp
    13. g++ -c -O2 -O2 -Wall -frtti -fexceptions -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_NO_DEBUG -DQT_PLUGIN -DQT_QT3SUPPORT_LIB -DQT3_SUPPORT -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREA
    14. D_SUPPORT -I"C:/Qt/4.1.0/include/QtCore" -I"C:/Qt/4.1.0/include/QtGui" -I"C:/Qt/4.1.0/include/Qt3Support" -I"C:/Qt/4.1.0/include" -I"C:/Qt/4.1.0/include/ActiveQt" -I"release" -I"."
    15. -I"C:/Qt/4.1.0/mkspecs/win32-g++" -o release\moc_MSUDevicePlugin.o release\moc_MSUDevicePlugin.cpp
    16. g++ -mthreads -Wl,-enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -Wl,-s -Wl,-s -shared -Wl,--out-implib,release\libGeMapMSUPlugin.a -o "release\GeMa
    17. pMSUPlugin.dll" release\MSUDevicePlugin.o release\MSUDeviceIcon.o release\moc_MSUDevicePlugin.o -L"C:\Qt\4.1.0\lib" -lQt3Support4 -lQtGui4 -lQtCore4
    18. Creating library file: release\libGeMapMSUPlugin.a
    19. release\MSUDevicePlugin.o(.text+0x896):MSUDevicePlugin.cpp: undefined reference to `MainWindow::canvas()'
    20. collect2: ld returned 1 exit status
    21. mingw32-make[1]: *** [release\GeMapMSUPlugin.dll] Error 1
    22. mingw32-make[1]: Leaving directory `C:/Documents and Settings/pdrummond/Desktop/src/morph/GeMapMSUPlugin'
    23. mingw32-make: *** [release] Error 2
    To copy to clipboard, switch view to plain text mode 

    Here's my pro file:

    Qt Code:
    1. TEMPLATE = lib
    2. TARGET +=
    3. DEPENDPATH += .
    4. CONFIG += plugin dll config qt exceptions rtti warn_on release
    5. QT += qt3support
    6.  
    7. # Input
    8. HEADERS += MSUDevicePlugin.h MSUDeviceIcon.h
    9. SOURCES += MSUDevicePlugin.cpp MSUDeviceIcon.cpp
    To copy to clipboard, switch view to plain text mode 

    You say on Linux I need to add "-rdynamic" to the main application - do I need to add anything to the main app for windows?

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Plugins confusion

    Unfortunately I can't help you much with windows as I'm not an expert on creating dlls in this environment. You can try the same, but as for now you can't even compile the plugin, so the issue has to be different.It is not a Qt issue in any way, rather a MinGW one. You could try asking the Trolls for help with this, maybe the qmakeconf for MinGW is incorrect.

  7. #7
    Join Date
    Feb 2006
    Posts
    32
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Plugins confusion

    Quote Originally Posted by wysota
    Unfortunately I can't help you much with windows as I'm not an expert on creating dlls in this environment. You can try the same, but as for now you can't even compile the plugin, so the issue has to be different.It is not a Qt issue in any way, rather a MinGW one. You could try asking the Trolls for help with this, maybe the qmakeconf for MinGW is incorrect.
    Ok, well thank you very much for your help - you answered my main question - what I am trying to do is possible and the problem lies in compliation/linking issues. Thanks again.

  8. #8
    Join Date
    Jan 2006
    Location
    Saint-Petersburg (Russia)
    Posts
    41
    Thanks
    1
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Plugins confusion

    You mean we need point compiler that's we compile dll ?
    Succes is 5% of talent and 95% of work!

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Plugins confusion

    Quote Originally Posted by blackliteon
    You mean we need point compiler that's we compile dll ?
    Yes, the compiler has to be aware of this (for whatever the reasons).

  10. #10
    Join Date
    Feb 2006
    Posts
    32
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Plugins confusion

    Quote Originally Posted by wysota
    As for Linux, you need to add a switch to the main app to allow plugins to resolve its symbols within the application binary. The switch is "-rdynamic".

    You can add it to the project file like this:

    QMAKE_LFLAGS += -rdynamic

    Remember to rerun qmake afterwards.
    Just an update to let you know this worked perfectly on Linux, thank you. Is this specified anywhere in the documentation?

    I still have problems with Windows but I will start a new thread for that as its an issue with DLLs specifically.

  11. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Plugins confusion

    Quote Originally Posted by Paul Drummond
    Is this specified anywhere in the documentation?
    In Qt documentation? No. I had to dig it out myself from ld docs and other sources when I needed it in my own program.

    I still have problems with Windows but I will start a new thread for that as its an issue with DLLs specifically.
    You might want to take a look at this thread, it looks very simmilar to your problem and the source of it is probably the same.

  12. #12
    Join Date
    Feb 2006
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Exclamation Re: Plugins confusion

    Please note that in order the plugins works in designer in windows the plugin dll must be compiled in release mode only.

Similar Threads

  1. Container plugins
    By Benne Gesserit in forum Qt Tools
    Replies: 4
    Last Post: 20th November 2008, 23:43
  2. Qt Plugins Error
    By nathanpackard in forum Qt Programming
    Replies: 1
    Last Post: 17th August 2007, 23:19
  3. Nightmares with plugins
    By KShots in forum Qt Programming
    Replies: 6
    Last Post: 8th February 2007, 16:46
  4. Arthur Plugins demos and designer
    By antonio.r.tome in forum Installation and Deployment
    Replies: 4
    Last Post: 21st March 2006, 14:01
  5. Plugins as small application
    By blackliteon in forum Qt Programming
    Replies: 4
    Last Post: 12th January 2006, 09:39

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.