Hi
i am having problem with Qt 4.7 "QDeclrativeView" component which is predefined
in Qt 4.7
following are the files of my test application
........................... project file...........................
QT += core gui
QT += declarative
TARGET = untitled7
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h \
test.h
FORMS += mainwindow.ui
OTHER_FILES += \
vaibhav.qml
........................... mainwindow.h file...........................
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
........................... test.h...........................
#ifndef TEST_H
#define TEST_H
#include<QDebug>
#include <QObject>
class testheader : public QObject
{
Q_OBJECT
Q_INVOKABLE void callfromqml()
{
qDebug()<<"function called";
}
};
#endif // TEST_H
...........................mainwindow.cpp...........................
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
........................... main.cpp...........................
#include <QtGui/QApplication>
#include "mainwindow.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
...........................vaibhav.qml...........................
import Qt 4.7
Rectangle {
width: 640
height: 480
MouseArea {
id: mouse_area1
anchors.fill: parent
onClicked: console.log("vaibhav"), test.callfromqml()
}
}
.............................................................................................................................................................................................
MY PROBLEM
i want to use a vaibhav.qml using ui setup because my project has existing UI
code
but it gives following output
vaibhav
"file:///home/maemo/untitled7/vaibhav.qml:10: TypeError: Result of expression
'test' [undefined] is not an object."
i know how to use "qdeclarative view" and "declarative engine"
but i do not know how to use declarative component from UI file.
help me with this
Regards
_______________________________________________
Qt-qml mailing list
[email protected]
http://lists.trolltech.com/mailman/listinfo/qt-qml