Have truble with binding
-
Hi community!
I have some truble with binding.
I whant to create a very simple programm for example, just for me. This program will show text wich i input in textbox 1 in textbox 2. I use pattern MVVM.
My exaple : http://rghost.ru/52524855
Thanks for help. -
Hi, and welcome to the Qt Dev Net!
Can you please post your code directly in the forum? Just add '@' before and after the code, and it will be formatted nicely. That will make it easier for everyone to read. :)
-
Yes, of course.
My main:
@ #include <qmlapplicationviewer.h>
#include <QApplication>
#include <QGuiApplication>
#include <QQmlEngine>
#include <qdeclarativecontext.h>
//#include <qqmlcontext>
#include <qqml.h>
#include <QtQuick/qquickitem.h>
#include <QtQuick/qquickview.h>
#include "MainModel.h"
#include "MainViewModel.h"int main(int argc, char *argv[])
{
QApplication app (argc, argv); //
// QmlApplicationViewer viewer;
// viewer.setOrientation(QmlApplicationViewer::ScreenOrientationAuto);
QmlApplicationViewer viewer;MainModel mainModel; //
// viewer.rootContext()->setContextProperty("model", new MainViewModel(mainModel));
// viewer.setMainQmlFile(QLatin1String("Button.qml"));
// viewer.showExpanded();QDeclarativeContext *ctxt = viewer.rootContext(); ctxt->setContextProperty("myModel", QVariant::fromValue(mainModel)); // viewer.setOrientation(QmlApplicationViewer::ScreenOrientationAuto); // viewer.setMainQmlFile(QLatin1String("Button.qml")); // viewer.showExpanded(); QDeclarativeView *view = new QDeclarativeView; // view->setSource(QUrl::fromLocalFile("Button.qml")); //
// //view->rootContext()->setContextProperty("model", new MainViewModel(mainModel));
view->show(); //return app.exec();
}
@Sorry for comments in code.
-
What do you mean by "problem with binding"? Please explain in more detail.
By the way, you should use classes that start with "QQml" or "QQuick". "QDeclarative is old and deprecated. See http://qt-project.org/doc/qt-5/qtquick-porting-qt5.html#c-code