Results 1 to 20 of 21

Thread: Call GUI Dll from non-Qt application

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    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.


  2. #2
    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.

  3. #3
    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.


  4. #4
    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?

  5. #5
    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.


  6. #6
    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?

  7. #7
    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.


  8. #8
    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.

  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: 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.


  10. #10
    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 

  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: 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.


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

    barak (11th July 2010)

  13. #12
    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

    You are correct !!

    Thank you very much it is WORKING !!! I have managed to show the dialog and work with it.

    Again, many thanks

    Keep on with the great job your doing.

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.