Calling Qapplication.exec multiple times in loop is possible, if yes how?



  • Calling the Qapplication.exec in a loop is not giving proper results. can you give the other way to do the same.

    @
    public static void main(String args[]) {
    QNetworkProxy proxy = new QNetworkProxy(ProxyType.HttpProxy,"web-proxy.sgp.hp.com", 8080);
    QNetworkProxy.setApplicationProxy(proxy);
    for(int i=0; i<2;i++){
    QApplication.initialize(args);
    HelloWebKit widget = new HelloWebKit();
    widget.show();

        QApplication.exec&#40;&#41;;
    

    }
    }
    @

    [formated the code properly, Tobias]



  • QApplication::exec() enters the event loop and does not return unless QApplication::exit() is called or if the event loop is already running.

    I'm not a Qt for Java expert but I assume the QApplication object has to be initialized once and QApplication::exec() has to be called just once too - as in C++. If you want two widgets just create two widgets. What is the purpose of the loop?

    @
    public static void main(String[] args)
    {
    QApplication.initialize(args);

    QNetworkProxy proxy = new QNetworkProxy(ProxyType.HttpProxy,
                                            "web-proxy.sgp.hp.com",
                                            8080);
    QNetworkProxy.setApplicationProxy(proxy);
    
    HelloWebKit widgetA = new HelloWebKit();
    widgetA.show();
    
    HelloWebKit widgetB = new HelloWebKit();
    widgetB.show();
    
    QApplication.exec&#40;&#41;;
    

    }
    @
    Brain to terminal. Not tested. Exemplary.



  • QApplication can only be started with exec() once. Not multiple times in a loop. If you really need separate event loops, you can using QEventLoop, but I really, really doubt you need that.



  • Actually I am not using the simple for loop. I have a simple dynamic java project in which i have included the webkit project as a jar, which renders the html page.
    So when the request comes to the servlet with url, the servlet calls the webkit application with the url.
    In webkit application, the Qapplication initalize, exec and quit are called once only and it opens the url.
    When the request comes first time, everything goes well. But when the request comes second time, it doesn't come up. Thats why i have made simple to ask... But basically initialze, exec and quit is called by one request after another request
    Please suggest something?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.