PDA

View Full Version : How to avoid putting one's name in a source code



sylas
16th January 2017, 15:54
Hi all! If I don't write: /home/sylvain/quick/main.qml it doesn't work. My name is sylvain. I think it is not normal to write his name in a code. . This thread continues the old thread "view possible in the design mode and qmlscene but not at the end or"run" ". Here, below, the code of main.cpp.

//main.cpp

#include <QGuiApplication>
#include <QQuickView>

int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
QQuickView view;
//view.setSource(QUrl::fromLocalFile("qrc:/main.qml"));//unfortunately doesn't work
view.setSource(QUrl::fromLocalFile("/home/sylvain/quick/main.qml"));
view.show();
return app.exec();
}

d_stranz
17th January 2017, 00:51
view.setSource(QUrl::fromLocalFile("qrc:/main.qml")); //unfortunately doesn't work

Are you sure this is the correct path to the resources in your qrc file? Also, resources are not a "local file" - that is a term used to describe files in your file system (e.g. disk drives). Simply use QUrl( "qrc:/main.qml" ) once you are sure the path is correct. You must also be sure that any other QML files you have created are also in the qrc file.

sylas
17th January 2017, 07:12
With your new line, it works very well ! Thank you very much. Here is your line: view.setSource(QUrl("qrc:/main.qml"));