How to auto-generate the entries of a QComboBox from file names?
-
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)
-
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)
@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.
-
@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.
-
@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?
@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()