Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Listing files in ComboBox
Qt 6.11 is out! See what's new in the release blog

Listing files in ComboBox

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 3.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kopfii
    wrote on last edited by
    #1

    Hello,

    iam newbie in Qt. I started a small Project by my own to learn more about the environment because it is also part of my apprenticeship. What iam looking for is a tutorial or a documentation about adding a path for the QComboBox. Iam aiming to list special files in it. But at the moment i just know that it is possible to add Elements to it by double clicking it in the Designer.
    How can i give a "Searchpath" to the QComboBox?

    Sorry for misunderstanding and kind regards
    Kopfii

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      You can add your items to the combo box using "addItem()":http://doc.qt.io/qt-5/qcombobox.html#addItem-2 and "addItems()":http://doc.qt.io/qt-5/qcombobox.html#addItems methods.

      Another option is to use the MVC approach and pass a model to the combo box, using "setModel()":http://doc.qt.io/qt-5/qcombobox.html#setModel method.

      (Z(:^

      1 Reply Last reply
      0
      • A Offline
        A Offline
        andre
        wrote on last edited by
        #3

        I'd use the model approach. It makes it very easy. You can use the QFileSystemModel to gather the files you need by using the appropriate filters, and just set it as the model for your combobox.

        1 Reply Last reply
        0
        • K Offline
          K Offline
          Kopfii
          wrote on last edited by
          #4

          Hey, Thanks alot. I Found another Function which is called "QDirIterator Class":http://doc.qt.io/qt-5/qdiriterator.html. I think i will take that function. I read the documentation of this file.

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andre
            wrote on last edited by
            #5

            Sure, that can work too. The benefit of using a QFileSystemModel is that:

            • it is already doing the QDirIterator for you
            • it works with large numbers of files because it is async
            • it will update if the contents of your file system change at runtime

            But, of course, you can make all of that yourself too, if you have enough time :)

            1 Reply Last reply
            0
            • K Offline
              K Offline
              Kopfii
              wrote on last edited by
              #6

              [quote author="Andre" date="1423057672"]Sure, that can work too. The benefit of using a QFileSystemModel is that:

              • it is already doing the QDirIterator for you
              • it works with large numbers of files because it is async
              • it will update if the contents of your file system change at runtime

              But, of course, you can make all of that yourself too, if you have enough time :)[/quote]

              Thanks. I tested it and its really a bit "stressful" so i came back to use the listWidget idea again... But thats development..

              edit

              How can i give a folderpath for the list? At the moment it looks like this, but its wrong..

              @#include "taskplaner.h"
              #include "ui_taskplaner.h"
              #include <QListWidgetItem>
              #include <QtCore>
              #include <QtGui>

              Taskplaner::Taskplaner(QWidget *parent) :
              QMainWindow(parent),
              ui(new Ui::Taskplaner)
              {
              ui->setupUi(this);
              ui->listWidget->addItem("P:\Test");
              }

              Taskplaner::~Taskplaner()
              {
              delete ui;
              }@

              edit 2

              Found a great Documentation to QFileSystemModel. I think i will give it a try. Iam a bit scary about testing new things as newbie...

              Thank you a lot :)

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved