Qt/C++ (and whatever else you tell me I need) to create a variable number of objects.

  • Hello everyone! I'm new to Qt but I've spent years programming with Python, php and designing Web user interfaces with CSS.

    I'm learning Qt/C++ to develop a new application for Ubuntu Touch using ubuntu components. I'd like to know how I could possibly generate a number of objects which isn't predefined in the editor but which depends on a variable which is set during the program flow.

    To explain me better I'll give a pair of examples:

    Let main.qml be our main design script in which we have a MainWindow with a set dimension. Inside the MainWindow we have a Flickable which is just a "scrollable" area.

    Now we have a folder containing an unknown X number of pictures. We want to open the folder, find the number and the QURLs to the picture, and for each of them "push" a QML QObject into the .qml file which in this case is actually an object which is decleared by a library in the Ubuntu.Components 0.1 (e.g. UbuntuShape) so that we can display all the images (a kind of picture gallery)

    The best way would be if C++ could actually inject QML code into the .qml file, but this sounds crazy and quite impossible...

    Another example is when we have a list of 'strings' which is retrieved using an http reqest (e.g rss feeds) and we want to "push" in the qml an object list which has all the 'strings' in it.

    Thanks a lot, any help is very appreciated!


    Can I let a parent vertical.contentSize attribute (which is an integer) be set by the distance between the first and the last child element? (so that all the elements can be see going "down" in the window) Or do you have better ideas?

  • Qt.createQmlObject() might be of use to create dynamic objects

  • that's awesome! :) thanks! It's a good start... with some arrays, loops, system control.. it's done

    I just need to know one more thing...
    If I create a program which interacts with the system (e.g.: get files in a folder) and install it on a mobile device, does it still work? :)

    1. One way to do it is, ensure the files are stored in a path relative to the folder where application is stored and use API QCoreApplication::applicationDirPath () to refer to the path where app is stored and access the contents relative to it.

    2. Alternatively, you can configure your .pro file to specify additional steps to copy files that are needed by application

Log in to reply

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