[solved]I cant use qrc files in my project
-
hi .
i make a text file and write this code on it :<!DOCTYPE RCC><RCC version="1.0">
<qresource>
<file>qml.qml</file>
</qresource>
</RCC>and save it as a qrc file .
whene i add this qrc file to my project qmlf.qrc and that .qml file are shown .
but whene i use it in my code it not work .QFile file("qrc:/qml.qml"); if (file.exists())msg.setText("exist"); else msg.setText("False"); msg.exec();
and return false .
(i use minGw and I have this proble whene use short path of file and I have to write complate path of files that i want to use even that file exist in my current )
-
@mahadin Try
:/qml.qml
instead ofqrc:/qml.qml
. Also you can createqrc
file from QtCreator itself instead of doing it manually.
Project > Add New > Qt > Qt Resource File -
@p3c0
its amazing!
QFile work OK!QFile file(":/qml.qml"); if (file.exists())msg.setText("exist"); else msg.setText("False"); msg.exec();
return exist
but QQmlComponent no !
QQmlEngine engine; QQmlComponent component(&engine,":/qml.qml"); QObject *object = component.create();
it return :
QQmlComponent: Component is not ready :( -
@mahadin Here you need to use
qrc:/qml.qml
. -
@p3c0
i test "qrc:/qml.qml"
it doesnt work! :| -
@mahadin Did you specify
QUrl
?QQmlEngine engine; QQmlComponent component(&engine,QUrl("qrc:/qml.qml"));
-
@p3c0
it work correctly by useing QUrl ;tanks :)
-
@mahadin Great. Happy Coding ...