Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
How to combine Qt/c++ file with a qml file in one project?
Hi everybody ,
I'm developing a c++ application using Qt and I'm using Qt quick for the design .The problem that I am facing is that I didn't know how to combine a qml file with a c++ file in the same project I mean how to make the link between them ?
I also want to know haw to apply the signal & slot concept with qml?
Can anybody help me please ?
This is covered thoroughly in "the documentation":http://qt-project.org/doc/qt-5/qtqml-cppintegration-topic.html.
Basically, there are 3 options:
- expose C++ class as a QML Singleton
- add C++ class as a root context property
- implement a QQuickItem or QQuickPaintedItem in C++ and use it in QML
Ok I will try and I hope I could fix the problem .
Do you yu know why an error occurs when I change the project file name ?
No. Please at least provide the error message here and I will try to help you.
Ok I actually changed the project file name then when i reopened the project and I pressed run the following errors are displayed :
D9024:unrecoognised source fil type '....%the previous project file name%', object file assumed
D9027:source file '....%the previous project file name%' ignored
C1803:cannot open source file %the previous project file name%' no such file or directory
I Tried the following solutions:
- clean->run qmake-> run
- the project file name cantained a space I've changed it to another name of one word(without spaces)
but the error persists
Probably a session problem. Please do this:
Exit Qt Creator
Browse to where your project is located
Delete <your project name>.pro.user
Start Qt Creator again
Open your project anew
Thanks sierdzio that worked very well !!
but can you explain for me how did you know that it is a session problem ?
It was an educated guess. Qt Creator uses .pro.user files to store local configuration of the project. If you change the name of the pro file wihtout setting up a new session, that file will hold corrupted session info.
Ok , Thank you for the clarification.