How to pass clicked event from button.qml to main source cpp to pop up a new window ?
Hi everybody :) ,
I'm using QML to design a GUI for my application.
My mainwindow link to mainwindow.qml file. On this mainwindow, i've design button but i don't know how to pass clicked event from this button to main source code cpp to pop up another windows ( I intend to swtich the link of mainwindow.qml to another .qml file )
Can somebody help me ? :(
Re: How to pass clicked event from button.qml to main source cpp to pop up a new wind
I'm not good at explaining so I'll just post some code. Marked the lines you should pay attention to with commends. Hope it helps ;)
mainwindow.h
Code:
#include <QMainWindow>
#include <QDeclarativeView>
#include <QDeclarativeContext>
#include <QDebug>
Q_OBJECT
public:
view = new QDeclarativeView(this);
view->rootContext()->setContextProperty("mainwindow",this); //this
view
->setSource
(QUrl("mainwindow.qml"));
this->setCentralWidget(view);
}
private:
QDeclarativeView *view;
public slots:
void click() { //this
qDebug() << "click";
}
};
mainwindow.qml
Code:
import QtQuick 1.0
Rectangle {
width: 100
height: 62
color: "red"
MouseArea {
anchors.fill: parent
onClicked: mainwindow.click() //this
}
}
Re: How to pass clicked event from button.qml to main source cpp to pop up a new wind
Thanks gouyoku so much, your post is very helpful for me ... sincerely ^^:)
Re: How to pass clicked event from button.qml to main source cpp to pop up a new wind
This indeed did the trick for me too but don't forget the Q_OBJECT keyword as I did at first.