How to open a new window in Qt Quick with a mouse area signal ?



  • Hello ,

    I'm developping an application using Qt quick and I'm still at the beginning . I created a personalized buttton and I created a mouse area but I didn't know how to open a new window with the signal onClicked .

    Thanks in advance.



  • Hi,

    Did you use "QtQuick Control Components":http://qt-project.org/doc/qt-5/qtquickcontrols-index.html? If so, it's a simple. All you need to create a window like this:
    @
    Window {
    id: newWindow
    //Other properties
    }
    @

    Than in you onClick signal add code like this:
    @
    newWindow.show();
    @

    The second way (I've used it in my app) is create a window dynamically. You can use some code like this:
    @
    function createWindow(parent)
    {
    try
    {
    var window = null;
    var tmp = Qt.createComponent(<the path to QML file with window source>);
    var options = { "id": "wndId",
    //Others property
    };
    window = tmp.createObject(parent, options);
    if(window !== null)
    {
    return window;
    }

        return null;
    }
    catch(exception)
    {
        console.log("EXCEPTION: "+exception);
        return null;
    }
    

    }
    @

    Use this function:
    @
    var wnd = createWindow(<some parent object>);
    if(wnd !== null)
    {
    wnd.show();
    }
    @

    The parent object is a object where you want to show window. It's maybe the id of main window where is your button.

    If you have any questions let me know I'll try to help you.



  • Thanks very much shav I will try the first way with QtQuick Controls components other ways I will ask you !!



  • Hi shav actually i created a new window(It only contains a white rectangle just to test) in a separate qml file but i didn't know how to make the include in the "main.qml".

    In fact I want to make each new page in a separate qml file so that the work would be more organized.



  • Hi ysing,

    I think will be grade if you use the function which I posted upper. All you need it's add the code to action which must show window.
    @
    var wnd = createWindow(<some parent object>);
    if(wnd !== null)
    {
    wnd.show();
    }
    @

    Could you check this "sample":http://dshav.com/qt_samples/testApp.zip.

    Also you can check the documentation about "Loader":http://qt-project.org/doc/qt-5/qml-qtquick-loader.html. This component of QML give you way load some QML file as a part of main file. But I don't use this component to load window.



  • Thank you very much for your help shav but my application should be in c++(I'm trying to avoid java) hence I will rewrite the code (since I'm still at the beginning) but with c++ classes and I will integrate qml .



  • [quote author="ysing" date="1407876082"]Thank you very much for your help shav but my application should be in c++(I'm trying to avoid java) hence I will rewrite the code (since I'm still at the beginning) but with c++ classes and I will integrate qml .
    [/quote]

    Hmm.... You can use the QML Plugin. Please check this "link":http://qt-project.org/doc/qt-5/qtqml-modules-cppplugins.html. If you want to create the logic of app on C++ and GUI on QtQuick, then plugin will help to you. In this case you can create GUI to show some datas to user and communicate with user (enter/select datas) and all logic methods (send/received datas to/from servers, calculate something, etc.) will be in C++ classes.



  • Ok , actually I'm reading a tutorial in the qt creator that contains an example with Qt qml c++ .

    If I found other problems I will definitely ask for help .



  • Hello ,

    I would like to ask when should I use the qml register type and when to use the plugin.

    Actually the concept is new to me and I feel confused and I don't know from where to start.
    I watched the video of Qt developer days 2011 It is discussing this task it clarified a little bit some concepts but I still find it ambiguous .

    Thanks in advance.


Log in to reply
 

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