Page 1 of 2 12 LastLast
Results 1 to 20 of 21

Thread: Call GUI Dll from non-Qt application

  1. #1
    Join Date
    Jul 2010
    Posts
    19
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Call GUI Dll from non-Qt application

    We have started to develop with the open SDK and came across a very crucial problem. If Qt SDK will be able to solve this issue will, probably, make the purchase.

    One of our components is Qt DLL which expose GUI dialogs. If we call it from other Qt applications, or even none Qt console application everything is fine and the DLL is able to show its dialogs. But, when we try to load dialogs from another none-Qt GUI application, Java application for instance, the application is not able to continue, no dialog is showed and we get the following error at the command line window we have run the application from: “QPixmap: It is not safe to use pixmaps outside the GUI thread”.

    We are testing it on Linux Ubuntu. All we need is to be able to show dialogs from Qt DLL being loaded by none-Qt GUI application.

  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: Call GUI Dll from non-Qt application

    You need to integrate Qt event loop with the other app's event loop, i.e. by periodically calling QCoreApplication::processEvents() instead of using threads.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jul 2010
    Posts
    19
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Call GUI Dll from non-Qt application

    The other application is not mine. It is using my DLL but I can not change its code. It is loading my DLL.

  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: Call GUI Dll from non-Qt application

    And how does it call your guis?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Jul 2010
    Posts
    19
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Call GUI Dll from non-Qt application

    The non-Qt GUI application is loading a DLL which uses my Qt-GUI dll. It needs to show some verify PIN dialog, which is implemented in my GUI Qt dll.

  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: Call GUI Dll from non-Qt application

    This doesn't answer my question. How does it call your code, in what conditions? And how does your code look like?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Jul 2010
    Posts
    19
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Call GUI Dll from non-Qt application

    My code is a static lib MyDll.a we have another shared library OurDll.so which links statically to MyDll.a(MyDll is the one with the GUI). There is another Java GUI application which links dynamically to the OurDll.so and loads it. When the GUI application performs verify PIN action it calls OurDll.so which in its turn use MyDll.a verify PIN function that have to show GUI dialog.

    My Code:

    This is called when OurDll.so is loaded.
    Qt Code:
    1. QApplication * a = 0;
    2. void initPkcsPinDialog(){
    3. if (!qApp)
    4. {
    5. a = 0;
    6. int argc = 1;
    7. char *argv[] = { "asePinDialog", NULL };
    8. a = new QApplication(argc, argv);
    9. }
    10. }
    11.  
    12. //This is calling the GUI dialog (VerifyPin3Des and VerifyPinSig are dialogs)
    13. bool aseLogin(aseVerifyData& aseData)
    14. {
    15. m_iLastSlotId = aseData.slotID;
    16.  
    17. if(aseData.pinType == KEY_TYPE_CHAL_RESP)
    18. {
    19. VerifyPin3Des *pinDlg = new VerifyPin3Des(aseData);
    20. m_pOpenDialog = pinDlg;
    21. pinDlg->exec();
    22. delete pinDlg;
    23. m_pOpenDialog = NULL;
    24. }
    25. else
    26. {
    27. VerifyPinSig *pinDlg = new VerifyPinSig(aseData);
    28. m_pOpenDialog = pinDlg;
    29. pinDlg->exec();
    30. delete pinDlg;
    31. m_pOpenDialog = NULL;
    32. }
    33.  
    34. m_iLastSlotId = 0;
    35. return true;
    36. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by wysota; 11th July 2010 at 10:31. Reason: missing [code] tags

  8. #8
    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: Call GUI Dll from non-Qt application

    You still didn't answer my original question.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #9
    Join Date
    Jul 2010
    Posts
    19
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default

    This one"how does it call your guis?"

    It is Java application we use in Linux. It loads the shared library OurDll.so which is statically linked with MyDll.a. OurDll.so expose a known interface and this is the interface the Java GUI application is using. I imagine that the GUI application is using some sort of get proc address to known function pointers and then use them.
    Last edited by wysota; 11th July 2010 at 10:57.

  10. #10
    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: Call GUI Dll from non-Qt application

    What I'm mainly after is whether both calls to your library are from the same thread (and which thread is it). Knowing JAVA world it is likely they are called from different threads and that is causing you trouble. GUI in Qt can only be accessed from the main thread (as noted several times in the docs, which you have surely read).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  11. #11
    Join Date
    Jul 2010
    Posts
    19
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default

    The main GUI thread is the Java application which has some other GUI and is implemented as GUI application which loads shared dlls. If I want to use GUI in my DLL I must have QApplication in order to have event loop for Qt, this is a must if I want to show GUI. But then the thread in my GUI dll is different thread here is a snapshot from the Linux:

    amiad@ubuntu:~$
    amiad@ubuntu:~$
    amiad@ubuntu:~$
    amiad@ubuntu:~$
    amiad@ubuntu:~$ "/home/amiad/Desktop/File Protector 5/FileProtector.sh"
    /home/amiad/Desktop/File Protector 5
    Starting Actalis File Protector v5 ...
    amiad@ubuntu:~$ Checking JVM version...
    [FPConfigFile]Pathname: /home/amiad/fp.users/
    QApplication: Invalid Display* argument

    amiad@ubuntu:~$
    amiad@ubuntu:~$ QPixmap: It is not safe to use pixmaps outside the GUI thread
    QObject: Cannot create children for a parent that is in a different thread.
    (Parent is QApplication(0x88da510), parent's thread is QThread(0x88d57c8), current thread is QThread(0x8bee0a0)
    QPixmap: It is not safe to use pixmaps outside the GUI thread
    QPixmap: It is not safe to use pixmaps outside the GUI thread

    One more thing only the Java GUI application is calling my DLL at a time. One call at a time.
    Last edited by wysota; 11th July 2010 at 11:21.

  12. #12
    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: Call GUI Dll from non-Qt application

    You still fail to understand me or you don't understand what threads are. I'm not asking whether your code is called by multiple threads at the same time, I'm asking whether both functions are called from the same thread (sequentially, not concurrently). The fact that the main thread of the process is executed by the java runtime says exactly nothing about which thread is calling your function. You can't answer my question without either debugging the java app, asking its author or inspecting its (app's, not author's) source code. So far we can only see Qt says your data is referenced by two threads. The only question is whether you start the thread in one of your dialogs or the java part does and what can you do to prevent it.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  13. #13
    Join Date
    Jul 2010
    Posts
    19
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Call GUI Dll from non-Qt application

    I understand, you ask if the Java application might be opening another thread and call my code from that thread, or is it calling it from its main thread, the GUI thread. You are correct I have no way of knowing it but is there a solution to each option? Is it possible to show GUI from shared library called by GUI application?

    Can I try some solution to any of the cases?

  14. #14
    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: Call GUI Dll from non-Qt application

    You can only access the GUI from the main (the one with QApplication object) thread so if you are currently working in context of a different thread, you need to order the main thread to operate the GUI for you and then return results back to the calling thread (you can use signals and slots or QCoreApplication::sendEvent()). Whether this will work or not depends on how the java application works. Also remember you need to have an event loop running to be able to receive signals across threads or use events. So either way you will have to integrate Qt event loop with the main app's event loop.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  15. #15
    Join Date
    Jul 2010
    Posts
    19
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Call GUI Dll from non-Qt application

    Can you show me in a few lines of code how do I integrate the Qt event loop with the main application's event loop?

  16. #16
    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: Call GUI Dll from non-Qt application

    No, sorry. I don't know how the java app works. I can only tell you that you need to force the application to periodically call QApplication::processEvents().
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  17. #17
    Join Date
    Jul 2010
    Posts
    19
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Call GUI Dll from non-Qt application

    OK one last question: if the Java application will not periodically call QApplication:rocessEvents() it will not work? I can not call QApplication:rocessEvents() from my code correct?
    Last edited by barak; 11th July 2010 at 12:01.

  18. #18
    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: Call GUI Dll from non-Qt application

    Quote Originally Posted by barak View Post
    OK one last question: if the Java application will not periodically call QApplication:rocessEvents() it will not work?
    It depends how you wish to implement it. You need to call your dialog in the context of the same thread the QApplication object was created in. The first thing I'd try would be to create the application object in the same function you are creating the dialog itself.

    I can not call QApplication:rocessEvents() from my code correct?
    Unless your code is called several times each second then no. But you should be able to inject some code into the java app (i.e. setup some timer or something like that). An alternative is to have a helper application in pure C++/Qt and only communicate with it from your two functions using some IPC mechanisms. Your init function would start the application and the other function would communicate with it through shared memory, pipes, sockets or similar mechanisms.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  19. #19
    Join Date
    Jul 2010
    Posts
    19
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Call GUI Dll from non-Qt application

    Some thing like this?

    Qt Code:
    1. bool aseLogin(aseVerifyData& aseData)
    2. {
    3. m_iLastSlotId = aseData.slotID;
    4. QApplication * a = 0;
    5. int argc = 1;
    6. char *argv[] = { "asePinDialog", NULL };
    7. a = new QApplication(argc, argv);
    8.  
    9. if(aseData.pinType == KEY_TYPE_CHAL_RESP)
    10. {
    11. VerifyPin3Des *pinDlg = new VerifyPin3Des(aseData);
    12. m_pOpenDialog = pinDlg;
    13. pinDlg->exec();
    14. delete pinDlg;
    15. m_pOpenDialog = NULL;
    16. }
    17. else
    18. {
    19. VerifyPinSig *pinDlg = new VerifyPinSig(aseData);
    20. m_pOpenDialog = pinDlg;
    21. pinDlg->exec();
    22. delete pinDlg;
    23. m_pOpenDialog = NULL;
    24. }
    25.  
    26. m_iLastSlotId = 0;
    27. return true;
    28. }
    To copy to clipboard, switch view to plain text mode 

  20. #20
    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: Call GUI Dll from non-Qt application

    Apart from memory leaks (why use pointers here if all objects are only used in local context?), yes.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  21. The following user says thank you to wysota for this useful post:

    barak (11th July 2010)

Similar Threads

  1. call a class
    By assismvla in forum Newbie
    Replies: 3
    Last Post: 24th May 2010, 12:57
  2. how to call mfc dll use qt?
    By yunpeng880 in forum Qt Programming
    Replies: 2
    Last Post: 12th March 2009, 04:32
  3. Replies: 3
    Last Post: 4th March 2008, 08:35
  4. Call QProcess without GUI
    By mattia in forum Newbie
    Replies: 8
    Last Post: 5th November 2007, 13:39
  5. Timer call
    By mahe2310 in forum Qt Programming
    Replies: 1
    Last Post: 28th March 2006, 08:57

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.