A positioning elements example



  • Hi all,
    I created a Qt Quick Application named position and wrote the components explained in this example in it.

    Here is the screenshot:

    0_1507101777752_Capture.PNG

    I tried to make use of the components possible by creating an instance of Repeater in main.qml. But as it's apparent, nothing (no component) is shown!

    Presumably I've forgotten to put some small but necessary line(s) of code there. The book doesn't talk about it either!!


  • Moderators

    @tomy
    what do you expect? You simply created an empty Repeater element. So of course nothing happens.


  • Moderators

    @raven-worx Lol beat me to it by like 10 seconds.



  • @tomy I have helped you in previous threads and I do it with pleasure. However, you seem to be avoiding the Qt's own documentation. I already gave you some links to documentation of some QML types and told how the Creator's Help view (the Help button in your screenshot) can be used. Every time you see a QML type (starting with an uppercase letter, like Repeater here) please use that Help and search for that type name. It has some example code where you can see how it's used. The qmlbook expects you can do that and doesn't explain the very basics. Take time reading the pages linked in http://doc.qt.io/qt-5/qmlreference.html (or those same pages in Creators Help view - it has the same documentation). It will give you answers to many, many questions. And every time you see a type name which isn't a component in your project search for it in the Creator Help.



  • @tomy BTW, I noticed that the project has a type named Repeater. It's misleading and misguided; the qmlbook has a base file named repeater.qml (with a lowercase letter) because the qml scene viewer can start execution with that. However, you have overridden the Qt's own type Repeater (with uppercase R). Rename that file to something else, like MyRepeater.qml. After that it depends on the contents of that file what is shown - if nothing, you can post the contents of that file after you have checked how the types used in that file are used.

    For simplicity the qmlbook seems to be using the scene viewer which will load a qml file directly and makes it an application window. I prefer to put everything in a "real" application with Window or ApplicationWindow. It's very good for practice to take the book's code and put it in an application window but it may require some small adjustement, like here.



  • @raven-worx

    You simply created an empty Repeater element. So of course nothing happens.

    But I created an empty element:

    Transformation {
                id: transformation
              }
    

    in my previous project (in this thread) and it showed almost everything!

    Anyway, thanks. This project may differ from that.


  • Moderators

    @tomy
    no you didn't use Transformation you used Column to layouts it's child items.
    It seems you are missing some very basics of QML. You should know what an elements does and why you use it. So please read the docs for every element you use in your code and it will clear many things up for you.



  • @Eeli-K said in

    @tomy I have helped you in previous threads and I do it with pleasure. However, you seem to be avoiding the Qt's own documentation. I already gave you some links to documentation of some QML types and told how the Creator's Help view (the Help button in your screenshot) can be used. Every time you see a QML type (starting with an uppercase letter, like Repeater here) please use that Help and search for that type name. It has some example code where you can see how it's used. The qmlbook expects you can do that and doesn't explain the very basics. Take time reading the pages linked in http://doc.qt.io/qt-5/qmlreference.html (or those same pages in Creators Help view - it has the same documentation). It will give you answers to many, many questions. And every time you see a type name which isn't a component in your project search for it in the Creator Help.

    I admit. I didn't know the book assumed the reader knows basics.
    About the Docs, most of the times, they have been confusing for Qt. I hope it isn't that way for QML.



  • @Eeli-K

    BTW, I noticed that the project has a type named Repeater. It's misleading and misguided; the qmlbook has a base file named repeater.qml (with a lowercase letter) because the qml scene viewer can start execution with that. However, you have overridden the Qt's own type Repeater (with uppercase R). Rename that file to something else, like MyRepeater.qml.

    Yes, it was the issue!
    The book declares it with a lower case letter, yes, but I myself changed it to that, because one of the admins here told me that components in QML should all have their first letter capitalised, and that was why I did that.
    By the way, the book has numerous writing mistakes.



  • @raven-worx

    no you didn't use Transformation you used Column to layouts it's child items.

    The Column was added later on. And it works even with this single instance as this recent project workes just by:

    MyRepeater {
            id: repeater
        }
    


  • @tomy said in A positioning elements example:

    The book declares it with a lower case letter, yes, but I myself changed it to that, because one of the admins here told me that components in QML should all have their first letter capitalised, and that was why I did that.
    By the way, the book has numerous writing mistakes.

    It was a good advice but you should first check if it's already 1) an existing QML/Quick/Components1/Components2 type or 2) an existing type elsewhere in that project or in a third party library which the project is using. Name clashes will be resolved by the engine but you and we may run into trouble if it's not clear which one is used. The qmlbook didn't use the lowercase name as a type name, it used it as a main entry qml file which is first opened by the engine. Usually it's named main.qml but it can be whatever you want. I would prefer something else than an existing type name, for example repeaterExample.qml would have been more descriptive and without problems. When you make it a component (your own type) you must capitalize the first letter so that it can be used as a type.

    There certainly are several problems with the qmlbook. It assumes certain things which are not necessarily obvious; it's old and doesn't cover e.g. Layouts; it may have mistakes or errors; not all coding practices are necessarily very good.

    The Qt's own documentation isn't without problems either, one of them is that it feels unorganized for a newcomer. The problem is seen in QML too, unfortunately. But unless you want to invest in a non-free book you have to read what is available. Just go through the pages in the link which I gave, skip those parts which don't look relevant at the moment, read those which seem to be relevant even if you don't understand them yet. You will thank yourself later for investing the time spent.



  • @Eeli-K said

    The qmlbook didn't use the lowercase name as a type name, it used it as a main entry qml file which is first opened by the engine. Usually it's named main.qml but it can be whatever you want.

    So the engine starts from a component that has a lowercase first letter. What if we have two ones, E.g., main.qml and repeater.qml?

    I would prefer something else than an existing type name, for example repeaterExample.qml would have been more descriptive and without problems. When you make it a component (your own type) you must capitalize the first letter so that it can be used as a type.

    Why should we need another start point while the IDE itself creates one named main.qml for us keeping us from deleting and creating a new .qml file?!

    The Qt's own documentation isn't without problems either, one of them is that it feels unorganized for a newcomer. The problem is seen in QML too, unfortunately. But unless you want to invest in a non-free book you have to read what is available.

    I was advised to read that online book for my purpose which is being able to write programs for smartphones. At the time I thought that book is either based on Qt or C++ but it's not and is a different language.
    By the way, I still hear that QML is very popular.

    So, if I want to read a "non-free" book on QML and suitable for a starter of QML, what book will you suggest me please?

    Just go through the pages in the link which I gave, skip those parts which don't look relevant at the moment, read those which seem to be relevant even if you don't understand them yet. You will thank yourself later for investing the time spent.



  • @tomy said in A positioning elements example:

    So the engine starts from a component that has a lowercase first letter. What if we have two ones, E.g., main.qml and repeater.qml?

    No, it must be defined somewhere anyways. E.g. in the "transformation" project from the qmlbook there's the project file which has:

    /* File generated by Qt Creator, version 2.4.1 */
    import QmlProject 1.1
    Project {
        mainFile: "transformation.qml"
    

    See also http://doc.qt.io/qt-5/qtquick-qmlscene.html. In a normal application the name is given in C++, usually in main.cpp (see that in an application project).

    Why should we need another start point while the IDE itself creates one named main.qml for us keeping us from deleting and creating a new .qml file?!

    Why not? Sometimes people may need to be able to for example choose between starting point qml files within one application or to load several files from C++. Sometimes they just want to change it to their liking. As for the framework (Qt, QML and Quick) it's better to be versatile. For the users, of course it's easier to use main.qml.

    So, if I want to read a "non-free" book on QML and suitable for a starter of QML, what book will you suggest me please?

    I haven't read any, maybe others can answer that. You can check https://wiki.qt.io/Books, and there has been some thread here about books, IIRC.



  • @Eeli-K

    No, it must be defined somewhere anyways.

    So having another lower case letter component with main.qml in the recent project will cause it not to work:

    0_1507188646125_Capture.PNG
    Because the engin starts from main.qml.

    See also http://doc.qt.io/qt-5/qtquick-qmlscene.html.

    I did and didn't find somwthing related to the issue.

    I haven't read any, maybe others can answer that.

    I continue reading that online book and try to use the hints (on using the Help window) more. But do you write great apps for smartphones (iOS and Android) using QML? If so and you haven't read any book on QML how did you learn it please?

    What is the use of Flow in this project please? It's a built-in type and defined this way:

    0_1507190574204_Capture.PNG



  • @tomy

    So having another lower case letter component with main.qml in the recent project will cause it not to work:

    Not necessarily. If you don't try to use that file from other files the project will work. You can have unused QML files as much as you want. They don't affect the rest of the program. They won't be evaluated runtime if they are not reached at all.

    I did and didn't find somwthing related to the issue.

    Qmlscene is used if you use the projects from the qmlbook. If you click the active configuration button in Creator, above Run and Debug buttons in the bottom left corner, you can see that it's run with QML Scene. Creator just passes the file defined in the project file to qmlscene.

    But do you write great apps for smartphones (iOS and Android) using QML? If so and you haven't read any book on QML how did you learn it please?

    Of course I write great apps! :) Well, maybe not so great. I have relatively little experience with QML but I have at least tested several programming languages, paradigms etc. C++, C, assembly, Lisp, Prolog, Javascript, Java, Python, Perl, shell scripting... Not to mention some years in a university learning software engineering and couple of years spent with C++ Qt. So it was not a big deal to learn QML quickly using only the Qt's own documentation and experimenting. Don't worry if you can't do the same.

    What is the use of Flow in this project please? It's a built-in type and defined this way:

    You're still making the same mistake with naming: Flow is indeed a built-in QML Quick type so you shouldn't give that name to you own type; call it 'MyFlow' (or 'FlowExample' or 'FlowExperimenting' or whatever you like), as you seem to do with Grid and Repeater. This MyFlow is a BrightSquare with a Flow added inside it, which has three squares inside it. See Flow in the Qt docs and each square in the project for what they have in turn.



  • @Eeli-K

    Not necessarily. If you don't try to use that file from other files the project will work. You can have unused QML files as much as you want. They don't affect the rest of the program. They won't be evaluated runtime if they are not reached at all.

    Yes, you're right and I knew that and in the prior post I had changed Grid to MyGrid to be usable.
    But the vague case would be why has the example created those many components with the same name as built-in types? What's its intention. Of course it has been waiting the reader to rename them (as I did) for use! ;)

    You're still making the same mistake with naming: Flow is indeed a built-in QML Quick type so you shouldn't give that name to you own type; call it 'MyFlow'

    Yes, I knew that. As I asked above, it was the example that has offered the example that way!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.