Results 1 to 2 of 2

Thread: How to use qwebkit module in a Qt library where no QApplication instance available?

  1. #1
    Join Date
    Feb 2011
    Posts
    12
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default How to use qwebkit module in a Qt library where no QApplication instance available?

    Here I have a problem:

    I want to create a QT library used by other C or C++ program. In this library, I use qtwebkit module to do some html and http work. According to QT's requirement, there must be a QApplication (not QCoreApplication) before qtwebkit objects, such as QWebPage can be used. However, we plan to use the library in a console application. In this situation, there's no main function in the library where I can define a QApplication object myself (QApplication a(argc, argv).

    Is there any suggestion on this? Can I init a QApplication object in the library myself? What's more, I'm using other threads in the library, which is more confusing.

  2. #2
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to use qwebkit module in a Qt library where no QApplication instance availabl

    Hi!

    Yes, you can create a QApplication yourself and give it a thread to live in. That's what I did in a library intended to be used by non qt applications.

    Qt Code:
    1. class QtAppLoop : public QThread
    2. {
    3. protected:
    4. void run() {
    5. static int argc = 1;
    6. static char* argv[] = {(char*)"dummy.exe", NULL };
    7. QCoreApplication* app = new QCoreApplication(argc,argv);
    8. app->exec();
    9. }
    10. };
    11.  
    12. QtAppLoop* apploop = 0;
    13.  
    14. void init()
    15. {
    16. if (QCoreApplication::instance() == NULL)
    17. {
    18. apploop = new QtAppLoop();
    19. apploop->start(QThread::LowPriority);
    20. }
    21. }
    To copy to clipboard, switch view to plain text mode 

    There are probably better solutions than this, but it worked for me!

    HIH

    Joh

Similar Threads

  1. Replies: 1
    Last Post: 18th December 2010, 11:05
  2. Replies: 8
    Last Post: 10th November 2010, 10:05
  3. SQL module and Thread-safe
    By banita in forum Qt Programming
    Replies: 6
    Last Post: 12th August 2010, 05:30
  4. Replies: 1
    Last Post: 7th February 2008, 10:23
  5. <QtGui/QApplication> vs. <QApplication>
    By seneca in forum Qt Programming
    Replies: 5
    Last Post: 25th January 2006, 10:58

Tags for this Thread

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.