Results 1 to 3 of 3

Thread: Minimal required files for creating a simple Qt Quick project

  1. #1
    Join Date
    Nov 2014
    Location
    Germany
    Posts
    69
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Windows Android

    Question Minimal required files for creating a simple Qt Quick project

    Hi,

    I’m on the way to port my applications (desktop) to mobile phones (android).
    I read a lot of times, that it’s strongly recommended to use QML instead of desktop Qt for mobile devices, because it would avoid lots of errors, is that right?

    Well, I tried starting a new Qt Quick project by using the Qt Quick tutorial. The example code in the tutorial looks like that:
    Qt Code:
    1. import QtQuick 2.3
    2.  
    3. Rectangle {
    4. id: simpleButton
    5. color: "grey"
    6. width: 150; height: 75
    7.  
    8. Text {
    9. id: buttonLabel
    10. anchors.centerIn: parent
    11. text: "button label"
    12. }
    13. }
    To copy to clipboard, switch view to plain text mode 
    The problem is, they “compile” or “run” the code above using qmlscene without using any other stuff (c++ source files, headers, resource files, pri files and so on…).
    In my case, I’d really like to use QtCreator and so, I have to create a project.
    When I do that, it creates a lot of files:
    1. the .pro file
    2. deployment.pri
    3. main.cpp
    4. main.qml
    5. MainForm.ui.qml

    When I run that project, everything works fine, but I don’t think I need all those files when Qt Quick tutorial only uses one qml file.

    When I remove all those files except the main.cpp (where the main.qml is loaded) and the main.qml and try to run the project, no errors occure, the executable is created and it runs, but nothing happens. There is no UI created…

    Does anyone know why? What am I doing wrong?

    That is my project:
    .pro file:
    Qt Code:
    1. TEMPLATE = app
    2.  
    3. QT += qml quick widgets
    4.  
    5. SOURCES += main.cpp
    6.  
    7. DISTFILES += main.qml
    To copy to clipboard, switch view to plain text mode 
    main.cpp
    Qt Code:
    1. #include <QApplication>
    2. #include <QQmlApplicationEngine>
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QApplication app(argc, argv);
    7.  
    8. QQmlApplicationEngine engine;
    9. engine.load("main.qml");
    10.  
    11. return app.exec();
    12. }
    To copy to clipboard, switch view to plain text mode 
    main.qml:
    Qt Code:
    1. import QtQuick 2.3
    2.  
    3. Rectangle {
    4. id: simpleButton
    5. color: "grey"
    6. width: 150; height: 75
    7.  
    8. Text {
    9. id: buttonLabel
    10. anchors.centerIn: parent
    11. text: "button label"
    12. }
    13. }
    To copy to clipboard, switch view to plain text mode 

    Can anyone help me with that?
    Thank you in anticipation!

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Minimal required files for creating a simple Qt Quick project

    Maybe you are running the program from a directory that is not the source directory, e.g. from a shadow build directory.

    One way to solve that is to put the QML file into a resource and build it into the app.

    Cheers,
    _

  3. #3
    Join Date
    Nov 2014
    Location
    Germany
    Posts
    69
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Windows Android

    Default Re: Minimal required files for creating a simple Qt Quick project

    Hi and thank you for your reply!
    Well, I just changed the relative paths using absolute ones, but there is still nothing happening. I never had this problems you describe when building projects, so the error is maybe somewhere else...

    Did you test the code on your system and it works? That would help me much to know that, because then I really have to check my QtCreator settings or create a resource file...


    [EDIT]
    I found my problem! When using a rectangle as basic element, I have to use QQuickView to load the QML file and show it manually. Otherwise I have to create a basic Window/ApplicationWindow in the QML file and load it like I did above using QQmlApplicationEngine...

    I hope this helps other desperate newbies with the same problem :-P

    Greetings
    Last edited by Binary91; 21st December 2014 at 11:27.

Similar Threads

  1. Replies: 4
    Last Post: 10th October 2014, 15:10
  2. QT minimal Glut code - no library linking required
    By rucs_hack in forum Qt Programming
    Replies: 5
    Last Post: 3rd October 2013, 08:30
  3. Creating sis files for C project Using QtCreator
    By mathi in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 3rd April 2012, 11:51
  4. Replies: 0
    Last Post: 28th April 2011, 07:27
  5. Replies: 1
    Last Post: 24th October 2009, 15:11

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.