Hi i am new to QML and trying to run a small QML program using c++ extension in Qt-5.4.0
here is my code app.qml
import QtQuick 2.1
import QtQuick.Controls 1.0
Button {
id: generate
text: qsTr("&Generate")
onClicked: generate.btn_clicked()
}
import QtQuick 2.1
import QtQuick.Controls 1.0
Button {
id: generate
text: qsTr("&Generate")
onClicked: generate.btn_clicked()
}
To copy to clipboard, switch view to plain text mode
button.h
#ifndef BUTTON_H
#define BUTTON_H
#include <QDeclarativeItem>
#include <QObject>
#include <QDebug>
#include <QWidget>
{
Q_OBJECT
public:
BButton();
Q_INVOKABLE void btn_clicked();
};
#endif
#ifndef BUTTON_H
#define BUTTON_H
#include <QDeclarativeItem>
#include <QObject>
#include <QDebug>
#include <QWidget>
class BButton : public QWidget
{
Q_OBJECT
public:
BButton();
Q_INVOKABLE void btn_clicked();
};
#endif
To copy to clipboard, switch view to plain text mode
button .cpp
#include "button.h"
BButton::BButton()
{
//nothing to write
}
void BButton::btn_clicked()
{
qDebug("THE GUI was clicked");
}
#include "button.h"
BButton::BButton()
{
//nothing to write
}
void BButton::btn_clicked()
{
qDebug("THE GUI was clicked");
}
To copy to clipboard, switch view to plain text mode
main.cpp
#include "button.h"
#include <qdeclarative.h>
#include <QDeclarativeView>
#include <QApplication>
int main(int argc, char *argv[])
{
//qmlRegisterType<PieChart>("Charts", 1, 0, "PieChart");
QDeclarativeView view;
view.
setSource(QUrl::fromLocalFile("app.qml"));
view.show();
return app.exec();
}
#include "button.h"
#include <qdeclarative.h>
#include <QDeclarativeView>
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
//qmlRegisterType<PieChart>("Charts", 1, 0, "PieChart");
QDeclarativeView view;
view.setSource(QUrl::fromLocalFile("app.qml"));
view.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
While executing using qmlscene the GUI was creating fine but on clicking the button it is showing the following error
file:///root/Btn_Sig/app.qml:7: TypeError: Property 'btn_clicked' of object Button_QMLTYPE_35(0x161c950) is not a function
Please tell me is there anything more to add in my code to generate the output or did i miss something.
Thanks in advance,
Rohith.G
Bookmarks