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

Thread: Deploy a Library

  1. #1
    Join Date
    May 2009
    Posts
    56
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Question Deploy a Library

    Hi all,

    I am trying to deploy a library developed with Qt (is meant to comunicate with a server thru TCP/ip QSockets). I trying to use this dll from a MFC application, i have used the dll the function call works fines but it seems that that the slot are no being called.

    I have start a Thread that ask for qApp if there is not, one is created and exec is called. But i seem that still dont work.

    My idea is that when the object that have signal and slot is created the qApp.exec(); is still no executed. I have observed this behavior in the log file.

    is there a way to know if qApp has the eventLoop running?
    which other way can i use, to achieve to use this dll from application that are not develop with Qt?

    Thanks for the answer.

    PD: i know this is not a mfc forum, but think this is a general problem to be able to deploy a dll that can be use by a external application no forcing the user to use Qt.

  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: Deploy a Library

    I'd have to see the code to be able to suggest a proper solution but a dirty workaround is to periodically call QApplication::processEvents() from within MFC 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.


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

    cafu1007 (15th June 2010)

  4. #3
    Join Date
    May 2009
    Posts
    56
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Question Re: Deploy a Library

    Qt Code:
    1. qint32 ClassD::connectToServer(QString IP, qint32 port)
    2. {
    3. qDebug() << "connectToServer";
    4. client = new CCltClient(this);
    5. connect(client, SIGNAL(signalConnectedToServer()), this, SLOT(slotConnectedToServer()));
    6. if (!client->connectToServer(IP, port))
    7. {
    8. return FORMAT_ERROR;
    9. }
    10. return OK;
    11. }
    12. void ClassD::slotConnectedToServer()
    13. {
    14. qDebug() << "slotConnectedToServer";
    15. }
    16. void Thread::close()
    17. {
    18. emit Kill_me();
    19. }
    20. void Thread::run()
    21. {
    22. qDebug("run");
    23. if (!qApp)
    24. {
    25. qDebug("no application running");
    26. int argc = 1;
    27. char *argv[] =
    28. { "setup", NULL };
    29. QApplication a(argc, argv);
    30. a.connect(this, SIGNAL(Kill_me()), &a, SLOT(quit()));
    31. qDebug("start running");
    32. a.exec();
    33. qDebug("application end");
    34. }
    35. }
    36.  
    37. static ClassD *pToFunc;
    38. Thread t;
    39. extern "C" __declspec(dllexport) int func1(void)
    40. {
    41. t.start();
    42. pToFunc = new ClassD();
    43. return pToFunc->connectToServer("127.0.0.1", 9190);
    44. }
    To copy to clipboard, switch view to plain text mode 

    I can connect to server and when i use the dll with the A Qt application Gui the slot is called but from the mfc does not.

    "I have modified the run"
    Last edited by cafu1007; 15th June 2010 at 09:31.

  5. #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: Deploy a Library

    You are creating a local QApplication object that goes out of scope immediately afterwards. The run() method doesn't make sense too - "if there is no qApp, call qApp".
    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. #5
    Join Date
    May 2009
    Posts
    56
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Deploy a Library

    HI Thanks for the answer i have fixed that in the code post that is how i am using it, but i got a warning "QApplication was not created in the main() thread.", and still does call the slot, i have tried also to decalre a as global pointer make new in the run but also do not work, sorry the previous mistake i was cutting and pasting.

  7. #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: Deploy a Library

    So what's the problem now?
    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. #7
    Join Date
    May 2009
    Posts
    56
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Deploy a Library

    the problem is the same the slot are not being called

  9. #8
    Join Date
    May 2009
    Posts
    56
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default

    Qt Code:
    1. void Thread::run()
    2. {
    3. qDebug("run");
    4.  
    5. if (!a)
    6. {
    7. qDebug("no application running");
    8. int argc = 1;
    9. char *argv[] =
    10. { "setup", NULL };
    11. a = new QApplication(argc, argv);
    12. QObject::connect(this, SIGNAL(Kill_me()), a, SLOT(quit()));
    13. qDebug("start running");
    14. a->exec();
    15. qDebug("application end");
    16. }
    17. else
    18. {
    19. QObject::connect(this, SIGNAL(Kill_me()), a, SLOT(quit()));
    20. qDebug("start running");
    21. a->exec();
    22. qDebug("application end");
    23. }
    24. }
    25.  
    26. static ClassD *pToFunc;
    27. Thread t;
    28. dllExport int func1(void)
    29. {
    30. if (!qApp)
    31. {
    32. qDebug("no application running");
    33. int argc = 1;
    34. char *argv[] =
    35. { "setup", NULL };
    36. a = new QApplication(argc, argv);
    37. }
    38. qInstallMsgHandler(debugWinMsgHandler);
    39. t.start();
    40. t.setPriority(QThread::HighPriority);
    41. qDebug() << "func1";
    42.  
    43. pToFunc = new ClassDl();
    44. return pToFunc->connectToServer("127.0.0.1", 9190);
    45. }
    To copy to clipboard, switch view to plain text mode 
    Like this work, i suppose cause of the priority of the thread the exec is called faster so when the function connect to server is called there is an application running, also i got this warning "QApplication::exec: Must be called from the main thread".

    back to one question how can i assure that qApp is being executing?(tha the called to exec() was done).

    Thanks

    I am not calling the thread to start the Qapplication .exec(). Now it works. Is strange that there is a Qt application running, and the qApp is not recognized and a new one is created, as my understanding the QApllication shoul be a singlenton,isn´t it? the CCltClient is a thread and when a connect to server is called the thread is started. Is there no need to call qApp.exec() so it start to recognize the signals? i got a bit confused.

    Qt Code:
    1. dllExport int func1(void)
    2. {
    3. qInstallMsgHandler(debugWinMsgHandler);
    4. if (!qApp)
    5. {
    6. qDebug("no application running");
    7. int argc = 1;
    8. char *argv[] =
    9. { "setup", NULL };
    10. a = new QApplication(argc, argv);
    11. }
    12. qDebug() << "func1";
    13. pToFunc = new ClassD();
    14. return pToFunc->connectToServer("127.0.0.1", 9190);
    15. }
    To copy to clipboard, switch view to plain text mode 
    this is how it looks the func1 now.
    Last edited by wysota; 15th June 2010 at 11:05.

  10. #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: Deploy a Library

    Thread can't be a subclass of QThread, this doesn't make sense. If it is a subclass of QThread then call QThread::exec() instead of QApplication::exec() (and create the application object in the main thread then). Otherwise use native means to create a thread and try instantiating the application object there.
    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. #10
    Join Date
    May 2009
    Posts
    56
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Deploy a Library

    Sorry i do not understand. shall i leave the the last form of func1, but also call t.start() and in the run call exec(). and leave it running for the time tha the application need it. is this what you mean?.. and what about the singleton of QApplication, why a new one is created, or at least why is no reconigzed as exiting....

    and as i said before i not calling any longer QApplication::exec(). but in the CCltClient in the run i call QThread::exec(). is this why it works?

    A last QApplication *a should remain globlal so it does not go out of scope....

    Thanks....

  12. #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: Deploy a Library

    Quote Originally Posted by cafu1007 View Post
    Sorry i do not understand. shall i leave the the last form of func1, but also call t.start() and in the run call exec(). and leave it running for the time tha the application need it. is this what you mean?..
    You need an event loop. Qt doesn't care if it is going to be the main event loop (QApplication::exec()) or a per-thread loop (QThread::exec()) as long as there is something to process events. So choose either approach and stick with it.

    and what about the singleton of QApplication, why a new one is created, or at least why is no reconigzed as exiting....
    Application object is not created automatically. You have to create it yourself (reglardless if you intend to use a per-thread event loop or the main event loop -- the application object has to exist somewhere).
    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. The following user says thank you to wysota for this useful post:

    cafu1007 (15th June 2010)

  14. #12
    Join Date
    May 2009
    Posts
    56
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Deploy a Library

    Quote Originally Posted by wysota View Post
    Application object is not created automatically. You have to create it yourself (reglardless if you intend to use a per-thread event loop or the main event loop -- the application object has to exist somewhere).
    Yeah but there a Qt Gui running so it should somewhere in the system or i am wrong

  15. #13
    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: Deploy a Library

    You said it was an MFC app. Now I'm confused.
    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.


  16. #14
    Join Date
    May 2009
    Posts
    56
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Deploy a Library

    yeah mfc app is using the dll that i have show the code. but in the same system there is also a gui appliction which was developed using Qt and QWidgets...
    Last edited by cafu1007; 15th June 2010 at 12:48.

  17. #15
    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: Deploy a Library

    Each application needs its own application object.
    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.


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

    cafu1007 (15th June 2010)

  19. #16
    Join Date
    May 2009
    Posts
    56
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default

    OK now i understand, thanks.

    HI, one last question if i am able to run the dll from a mfc, thats means that the dll can be used with any c++ compiler or there is some exceptions or how do i know that
    Last edited by wysota; 15th June 2010 at 13:53.

  20. #17
    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: Deploy a Library

    It can be used with the same type (and possibly version) of compiler it was compiled with. You can't use MinGW compiled DLL with MSVC compiled application (at least not directly).
    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. #18
    Join Date
    May 2009
    Posts
    56
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Deploy a Library

    but i am using to compile the dll MinGW, and to compiled the gui MFC Visual C++ 2005. and it works

  22. #19
    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: Deploy a Library

    It's hard for me to believe it as MinGW and MSVC use different name mangling schemes and create import libraries with different (incompatible) filenames. Check if you are really using two different compiler families.
    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.


  23. #20
    Join Date
    May 2009
    Posts
    56
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Deploy a Library

    when i used the libCDll.a file i rename it to CDll.lib and it works.

Similar Threads

  1. Has anybody ever able to deploy qt application?
    By Tarun in forum Installation and Deployment
    Replies: 16
    Last Post: 22nd February 2010, 09:08
  2. How to deploy application using shared library in Linux
    By cutie.monkey in forum Installation and Deployment
    Replies: 9
    Last Post: 21st January 2010, 18:41
  3. Deploy on Windows XP ?
    By Anti in forum Newbie
    Replies: 3
    Last Post: 24th September 2009, 21:19
  4. Deploy Qt application on Mac OS X
    By giandrea77 in forum Installation and Deployment
    Replies: 3
    Last Post: 11th February 2009, 09:34
  5. Deploy app under many Mac OS and architecture
    By mourad in forum Installation and Deployment
    Replies: 2
    Last Post: 8th April 2008, 10:31

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.