1

calling Qapplication.exec in a loop is not giving proper results. can somebody give me some other idea to do the below thing..thanks

something like this

public static void main(String args[]) {
        QNetworkProxy proxy = new QNetworkProxy(ProxyType.HttpProxy,Proxyname, port);
    QNetworkProxy.setApplicationProxy(proxy);
    for(int i=0; i<2;i++){
        QApplication.initialize(args);

                HelloWebKit widget = new HelloWebKit();
                widget.show();

                QApplication.exec();
    }
    }
Anjna
  • 11
  • 2

3 Answers3

2

QApplication.exec() typically doesn't return until you quit your program. The documentation mentions that control may not return to the code calling QApplication.exec() in some circumstances.

If you want to run two instances of QApplication simultaneously, you may have to invoke two separate programs or invoke the same program twice with different command line arguments.

Another possibility would be to use two threads, but I wouldn't recommend that if you don't have a very convincing reason for doing so.

menjaraz
  • 7,551
  • 4
  • 41
  • 81
Dirk
  • 1,184
  • 6
  • 22
0

From a Qt/C++ perspective, your widgets can all share the same Qt message pump started by exec().

public static void main(String args[]) {
    NetworkProxy proxy = new QNetworkProxy(ProxyType.HttpProxy,Proxyname, port);
    QNetworkProxy.setApplicationProxy(proxy);
    QApplication.initialize(args);

    for(int i=0; i<2;i++){
        HelloWebKit widget = new HelloWebKit();
        widget.show();
    }
    QApplication.exec();
}

Still this being said I have not worked with Qt Jambi, and the code looks like it does not run as such.

hg.
  • 324
  • 1
  • 13
0

An excerpt from QApplication documentation:

QApplication contains the main event loop, where all events from the window system and other sources are processed and dispatched.

By design, there should be one only one main event loop in an application.

exec is inherited from QCoreApplication.

QApplication.exec enters the main event loop and waits until exit() is called.

Invoking QApplication.exec many times is a nonsence. It should be done once and for all.

menjaraz
  • 7,551
  • 4
  • 41
  • 81