Hello everybody,
I created a graphical interface with QML, I would like to integrate it in Visual studio 2012 to do some treatements and operations with C++
I did some research in NET, I found an exemple with QDeclarativeView
TestListView
::TestListView(QWidget *parent
){
ui= new QDeclarativeView;
QString filePath
= QDir::currentPath() + "/main_view.qml";
ui
->setSource
(QUrl::fromLocalFile(filePath
));
setCentralWidget(ui);
ui->setResizeMode(QDeclarativeView::SizeRootObjectToView);
root = ui->rootObject();
ui->rootContext()->setContextProperty("Window", this);
std::vector<std::string> dataTable;
dataTable.push_back("C++");
dataTable.push_back("Java");
dataTable.push_back("Python");
QList<QObject*> dataList;
for(int i=0; i<dataTable.size(); i++)
{
color = (color == "gray") ? "silver" : "gray" ;
dataList.
append(new DataObject
(QString(dataTable.
at(i
).
c_str()), color
));
}
ui
->rootContext
()->setContextProperty
("dataModel",
QVariant::fromValue(dataList
));
}
TestListView::TestListView(QWidget *parent)
: QMainWindow(parent)
{
ui= new QDeclarativeView;
QString filePath = QDir::currentPath() + "/main_view.qml";
ui->setSource(QUrl::fromLocalFile(filePath));
setCentralWidget(ui);
ui->setResizeMode(QDeclarativeView::SizeRootObjectToView);
root = ui->rootObject();
ui->rootContext()->setContextProperty("Window", this);
std::vector<std::string> dataTable;
dataTable.push_back("C++");
dataTable.push_back("Java");
dataTable.push_back("Python");
QList<QObject*> dataList;
QString color = "gray";
for(int i=0; i<dataTable.size(); i++)
{
color = (color == "gray") ? "silver" : "gray" ;
dataList.append(new DataObject(QString(dataTable.at(i).c_str()), color));
}
ui->rootContext()->setContextProperty("dataModel", QVariant::fromValue(dataList));
}
To copy to clipboard, switch view to plain text mode
But QtDeclarative works only with QtQuick 1.0
I'm using QtQuick 2.0 so I tried to use QQuickView :
ui= new QQuickView;
QString filePath
= QDir::currentPath() + "/main_view.qml";
ui
->setSource
(QUrl::fromLocalFile(filePath
));
setCentralWidget(ui); // QQuickView is incompatible with QWidget
ui->setResizeMode(QQuickView::SizeRootObjectToView);
root = ui->rootObject();
ui->rootContext()->setContextProperty("Window", this);
ui= new QQuickView;
QString filePath = QDir::currentPath() + "/main_view.qml";
ui->setSource(QUrl::fromLocalFile(filePath));
setCentralWidget(ui); // QQuickView is incompatible with QWidget
ui->setResizeMode(QQuickView::SizeRootObjectToView);
root = ui->rootObject();
ui->rootContext()->setContextProperty("Window", this);
To copy to clipboard, switch view to plain text mode
Someone can resolve this error
best regards
Bookmarks