Adding some path to a QListView

  • how to add new element to a QListView ? i I tried with :

    @QString path;
    path = QFileDialog::getOpenFileName(this,
    tr("Choose a file to open"),
    tr("Images (*.png *.jpg)")) ;

    new QListViewItem(ui->listView, path);@
    but its not work.

  • bq. new QListViewItem(ui->listView, path);

    Initialised to ?

    And you want to use QListView ,not "QListWidget": ?

  • what do you mean by initialized to ? plz more details
    yes i want use QListView

  • Am sorry if am not clear.
    I think , there is a problem with line 7. Initialization issue.

    EDIT : you can have a look at "this": .Hope its useful to you.

  • If you want to use QList_View_, then you are using it with a model, a QAIM subclass. If you want to add something to the displayed list, you have to add that piece of data to the model. The view will then display it. You are not telling us what type of model you are using, so it is hard to tell you how to do this.

    In your small code sample, you are trying to do something that looks more like how you would work with QListWidget. That will not work. Perhaps your model is a QStandardItemModel? In that case, you can add a new item to this model with a syntax that looks a bit like what you are trying to do.

Log in to reply

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