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. How to auto-generate the entries of a QComboBox from file names?
Forum Updated to NodeBB v4.3 + New Features

How to auto-generate the entries of a QComboBox from file names?

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 484 Views
  • 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.
  • U Offline
    U Offline
    Urbi
    wrote on last edited by
    #1

    I want to add some new functions to a complex Qt project. For this I need to generate the entries of a QComboBox automatically from the names of files, which are located in a certain directory. And as soon as I select one of the entries, the content of the corresponding file should be copied automatically to another file.

    Example:
    A directory c:\dat contains the files: "XYZ-1", "XYZ-2", and "XYZ-3"
    So my QComboBox "dat_box" should create the entries "XYZ-1", "XYZ-2", and "XYZ-3".
    As soon as I select e.g. "XYZ-2", the content of the file "XYZ-2" shall be copied automatically into an existing file "XYZ" (and replace its content).

    How can I program this? (My C++ programming skills are not the best. Please be so kind and explain it well enough or at best give me a concrete example)

    jsulmJ 1 Reply Last reply
    0
    • U Urbi

      I want to add some new functions to a complex Qt project. For this I need to generate the entries of a QComboBox automatically from the names of files, which are located in a certain directory. And as soon as I select one of the entries, the content of the corresponding file should be copied automatically to another file.

      Example:
      A directory c:\dat contains the files: "XYZ-1", "XYZ-2", and "XYZ-3"
      So my QComboBox "dat_box" should create the entries "XYZ-1", "XYZ-2", and "XYZ-3".
      As soon as I select e.g. "XYZ-2", the content of the file "XYZ-2" shall be copied automatically into an existing file "XYZ" (and replace its content).

      How can I program this? (My C++ programming skills are not the best. Please be so kind and explain it well enough or at best give me a concrete example)

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Urbi Use https://doc.qt.io/qt-5/qdir.html#entryList-1 to get a list of all files in the directory and add these files to your combo box.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      U 1 Reply Last reply
      4
      • jsulmJ jsulm

        @Urbi Use https://doc.qt.io/qt-5/qdir.html#entryList-1 to get a list of all files in the directory and add these files to your combo box.

        U Offline
        U Offline
        Urbi
        wrote on last edited by
        #3

        @jsulm Thanks, that should work. Do you also know how I can do it to copy the content of the selected file to a specified file?

        Christian EhrlicherC 1 Reply Last reply
        0
        • U Urbi

          @jsulm Thanks, that should work. Do you also know how I can do it to copy the content of the selected file to a specified file?

          Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Urbi said in How to auto-generate the entries of a QComboBox from file names?:

          Do you also know how I can do it to copy the content of the selected file to a specified file?

          See QFile::copy()

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          1 Reply Last reply
          2

          • Login

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