Skip to content
QtWS25 Call for Papers
  • 0 Votes
    4 Posts
    133 Views
    JonBJ

    @jdent
    You have to iterate through the rows looking for the value you want.
    If you use a QSortFilterProxyModel you can take advantage of binary search for speed if you sort by primary key. QSqlRelationalTableModel is not important here, all that gives is a "lookup" on one field to map e.g. an integer value to a corresponding string from a related table for display.

  • 0 Votes
    12 Posts
    265 Views
    Christian EhrlicherC

    Please read the docs of submitAll():
    "In OnManualSubmit, on success the model will be repopulated. Any views presenting it will lose their selections."

  • 0 Votes
    7 Posts
    287 Views
    B

    @hemang_1711 I have just gone back to your original post and I see again what originally confused me.

    If you recall, I asked about GraphParam, which you are trying to access in your QML. I looked for this in your model implementation, but your model does not have a role "GraphParam".

    You do have a role "GraphList", which seems to return the first element of the list member named GraphParam in the GraphModelItem struct in your implementation. Although GraphParam is the name of the struct member, QML does not know anything about this name. It only sees the names you have defined in your roles.

  • 0 Votes
    3 Posts
    215 Views
    S0ulM1keS

    @GrecKo the problem is, that GridView releases it delegates when model's elements is removed. It provokes Image to reload if delegate is shown again. No meter if I set cache: true

    Such a shame that GridView don't have reuseItems like ListView

    I've come with next decision. I've created Repeater containing Image that use source model. GridView's delegate Image use Repeater's function itemAt() giving delegate's index after mapping to source model:

    //Image in deleagte Image { Component.onCompleted: { source = appModelImages.loadImage(appFilterModel.mapRowToSource(parent.delegateIndex)) // custom implementation } ... } //Repeater Repeater { id: appModelImages visible: false function loadImage(index){ return itemAt(index).source } model: AppModel delegate: Image { visible: false asynchronous: true source: model.boxart } }

    This may be not the best decision, but "faster" than create own delegate pool for GridView. Didn't see any examples of implementing mechanism like this. Repeater should work fine, as it relays on source model. And as I expected, images live when source model does.

  • QVariant to QList

    Solved General and Desktop
    13
    0 Votes
    13 Posts
    1k Views
    mzimmersM

    @JoeCFD said in QVariant to QList:

    Understand. Thiink about you can never be number 1 anymore if you play chess.

    Oddly enough, that was never a concern of mine.

  • 0 Votes
    5 Posts
    319 Views
    P

    @SGaist
    That's What i want bro Really Thank you <3

  • 0 Votes
    7 Posts
    571 Views
    BeaverShallBurnB

    @JonB

    Huge thanks, you solved the puzzle for me!

  • 0 Votes
    3 Posts
    380 Views
    G

    @Gojir4 thank you so much

  • 0 Votes
    2 Posts
    293 Views
    O

    The problem arises from the usage of the method m_model.setStringList(). The latter always clear the previous data, hence the index always reset upon its call.

    Solution:

    Use m_model.setStringList() only in the constructor to init the model.

    After that manually insert the row on the model and set the data for the respective row. This can be achieved with a simple modification in the slot method.

    MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) { ui->setupUi(this); m_model.setStringList({"1","2"}); ui->comboBox->setModel(&model); } void MainWindow::on_pushButton_clicked() { m_model.insertRow(model.rowCount()); m_model.setData(model.index(model.rowCount()-1), "3"); }

    In the example above, "3" is appended to the list model without changing the current index from the QComboBox.

  • 0 Votes
    5 Posts
    895 Views
    N

    Hi @LeLev,

    I tried your solution. Its showing the image. That is fine.
    Now if i have more elements then its filling in the same space.
    I need to scroll thorough the screen to see the elements.
    How to do that ? How should I use Flickable in this case.

    Note: For example: If the screen layout is 500x500, and each element size id 50x50,
    then i should only see 16 elements initially. I have to scroll down on the screen to see the remaining elements.

  • 0 Votes
    1 Posts
    339 Views
    No one has replied
  • 0 Votes
    1 Posts
    336 Views
    No one has replied
  • 0 Votes
    2 Posts
    393 Views
    J.HilkJ

    @jeanmilost
    I can't answer all your questions, as I'm not an expert on Qt's Model/View system, what I do know is,

    that all models have a QAbstractItemModel as base model and that is also the ABI for all views.
    For that reason alone, you can assign all models to all views. You will however not get a useful representation of all your data in all views.

    As I understand it, and anyone fell me to correct me here, the other higher level classes of models are only there to make your life easier, as in you do not have to implement all functions/functionalities of the whole AbstractItemModel class

  • 0 Votes
    4 Posts
    573 Views
    sierdzioS

    @daljit97 said in Unable to edit QSqlTableModel from QML:

    , Qt::EditRole);

    Then you should probably pass the role and not editRole, otherwise model won't know which column to update.

  • 0 Votes
    10 Posts
    781 Views
    T

    @Christian-Ehrlicher It caches entries that could have fairly high resolution images in them. 100MB consumed is quite reasonable for my particular use case. I've solved my problem my creating a general-purpose list model class which does not retain too many recent items in memory, and then implementing an application-specific subclass that will automatically produce small, low-resolution thumbnails and save them to a separate table to allow for faster loading later on.

  • Benefit of the model index

    Unsolved General and Desktop
    4
    0 Votes
    4 Posts
    473 Views
    VRoninV

    On the model you are free to expose the internal structure. QStandardItemModel does it by exposing QStandardItem for example. However if you don't want to make use of the QAbstractItemModel interface and its seamless integration with views and delegate and just use your custom classes why bother subclassing a model in the first place? Just start from scratch. I'm not suggesting this is the most efficient way in terms of developer time but if performance is the only priority then feel free to go as low level as you can

  • 0 Votes
    6 Posts
    5k Views
    P

    After thinking about this problem more and looking at the interface for QAbstractProxyModel, I am beginning to think that a subclass of a proxy model is not the answer. I am wondering if the best course of action would be to create a new model which keeps a pointer to my base model. Every time the various data changed signals are emitted from the base model, my "proxy" model determines if a new sequence has been found. It then keeps track of all the various sequences in its own internal data structure which keeps QPersistenModelIndex indexes into the base model. Then my "proxy's" data() method would use these indexes to get the real data from the underlying model but parsed into the correct format.

    Do this sound like a better approach?

    In this case, I am also wondering how to display my data as a table where each row could have a different number of columns. Perhaps I could keep track of the row with the maximum number of columns and return this in columnCount()? Then my data() method would just return QVariant() for columns that don't exist in a given row.