Results 1 to 5 of 5

Thread: QLibrary resolving functions

  1. #1
    Join Date
    Sep 2008
    Posts
    24
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default QLibrary resolving functions

    Hi guys,

    I have a widget that uses QLibrary to load a DLL and resolve its functions into widget specified functions. Here's what I mean

    Qt Code:
    1. myWidget::myWidget(QWidget *parent)
    2. : QWidget(parent)
    3. {
    4. myLib = new QLibrary; // library to hold DLL
    5. }
    6.  
    7. void myWidget::openDLL(QString DLL_File_Name)
    8. {
    9. bool operation;
    10.  
    11. typedef bool (*MyPrototypeOne)();
    12. MyPrototypeOne Open = (MyPrototypeOne) myLib->resolve("OD");
    13.  
    14. operation = Open();
    15.  
    16. emit Success(operation);
    17.  
    18. }
    19.  
    20. void myWidget::run(QString DLL_File_Name)
    21. {
    22. typedef int (*MyPrototypeTwo)();
    23. MyPrototypeTwo RunFunc = (MyPrototypeTwo) myLib->resolve("RF");
    24.  
    25. int i = RunFunc();
    26. }
    To copy to clipboard, switch view to plain text mode 

    What I want to know is, is it possible to have these resolved functions accessible throughout the widget? It would be nice not to have to continually pass the file name and prototype the function but rather resolve it once and have it accessible everywhere.

    Any help appreciated.

  2. #2
    Join Date
    Apr 2010
    Location
    Rostov-na-Donu, Russia
    Posts
    153
    Thanks
    2
    Thanked 26 Times in 23 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QLibrary resolving functions

    your example wouldn't work, because you didn't give DLL_File_Name to QLibrary object
    call
    Qt Code:
    1. myLib->setFileName( DLL_File_Name );
    To copy to clipboard, switch view to plain text mode 
    in your openDLL and run functions.
    but there's a better idea to give dll name in constructor, like this
    Qt Code:
    1. class myWidget : public QWidget
    2. {
    3. public:
    4. myWidget(QWidget *parent, const char * const dllFileName )
    5. : QWidget(parent)
    6. , m_dll( dllFileName )
    7. {
    8. }
    9. protected:
    10. QLibrary m_dll;
    To copy to clipboard, switch view to plain text mode 
    and the next. Check, that your function pointers are not zero
    Qt Code:
    1. MyPrototypeOne Open = (MyPrototypeOne) m_dll.resolve("OD");
    2. if ( Open )
    3. {
    4. ... // do something with Open
    5. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Sep 2008
    Posts
    24
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QLibrary resolving functions

    Thanks but maybe I wasn't being clear. I have a widget working perfectly (the above was just a basic demonstration of what I'm on about).

    What I'm wondering is if there's a way to call the resolved function "Open" in the run function and vice versa.

  4. #4
    Join Date
    Apr 2010
    Location
    Rostov-na-Donu, Russia
    Posts
    153
    Thanks
    2
    Thanked 26 Times in 23 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QLibrary resolving functions

    What I'm wondering is if there's a way to call the resolved function "Open" in the run function and vice versa
    Of course you can. Just move declaration
    Qt Code:
    1. MyPrototypeOne Open
    To copy to clipboard, switch view to plain text mode 
    into class declaraion (.h-file) as a member of your class, resolve them in constructor and use in any functions within your class

  5. The following user says thank you to borisbn for this useful post:

    td (7th April 2010)

  6. #5
    Join Date
    Sep 2008
    Posts
    24
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QLibrary resolving functions

    Ahh! Thanks! My brain must be on go-slow today.

Similar Threads

  1. Returning a QString to a QLibrary
    By johnmauer in forum Qt Programming
    Replies: 3
    Last Post: 14th February 2010, 12:27
  2. Replies: 3
    Last Post: 18th January 2010, 10:35
  3. QLibrary in PyQt
    By Urthas in forum Qt Programming
    Replies: 0
    Last Post: 30th October 2009, 18:46
  4. The problem with QLibrary, help me!
    By dungsivn in forum Qt Programming
    Replies: 4
    Last Post: 17th January 2008, 14:03
  5. Qlibrary
    By rianquinn in forum Qt Programming
    Replies: 5
    Last Post: 4th February 2006, 12:23

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.