I have one window which has a button named "..." which open an other window which has also a button named "..." which open a QFileDialog. Next to the button of the second window, there are 10 QLineEdit to get 10 files. With the QFileDialog, I can't take a mp3 file and put his name in the first QLineEdit. How can I do ? And if the first QLineEdit is already took, how can I put the name of a mp3 file in the second QLineEdit ?
The file "main.h" has just the include of Qt. Here is my code and I tried many solutions without success :
#include "main.h"
int main(int argc, char **argv)
{
QApplication program(argc, argv);
/* ******************** First Window ******************** */
QWidget window;
QVBoxLayout layout;
window.setWindowTitle("Programme");
window.setWindowIcon(QIcon(":/Images/Images/Bouclier.png"));
window.setFixedSize(450, 400);
QHBoxLayout layouttop;
QLabel labeltop("Nom du programme :");
QLineEdit lineedittop;
layouttop.addWidget(&labeltop);
layouttop.addWidget(&lineedittop);
QHBoxLayout layoutmiddle;
QPushButton buttonnext;
QPushButton buttonprevious;
QPushButton buttonetc("...");
QLineEdit line0;
QLineEdit line1;
QLineEdit line2;
QLineEdit line3;
QLineEdit line4;
QLineEdit line5;
QLineEdit line6;
QLineEdit line7;
QLineEdit line8;
QLineEdit line9;
QVBoxLayout layoutleft;
layoutleft.addWidget(&buttonnext);
buttonnext.setIcon(QIcon(":/Images/Images/Haut.png"));
layoutleft.addWidget(&buttonprevious);
buttonprevious.setIcon(QIcon(":/Images/Images/Bas.png"));
QVBoxLayout layoutcenter;
layoutcenter.addWidget(&line0);
layoutcenter.addWidget(&line1);
layoutcenter.addWidget(&line2);
layoutcenter.addWidget(&line3);
layoutcenter.addWidget(&line4);
layoutcenter.addWidget(&line5);
layoutcenter.addWidget(&line6);
layoutcenter.addWidget(&line7);
layoutcenter.addWidget(&line8);
layoutcenter.addWidget(&line9);
line0.setReadOnly(true);
line1.setReadOnly(true);
line2.setReadOnly(true);
line3.setReadOnly(true);
line4.setReadOnly(true);
line5.setReadOnly(true);
line6.setReadOnly(true);
line7.setReadOnly(true);
line8.setReadOnly(true);
line9.setReadOnly(true);
QVBoxLayout layoutright;
layoutright.addWidget(&buttonetc);
layoutmiddle.addLayout(&layoutleft);
layoutmiddle.addLayout(&layoutcenter);
layoutmiddle.addLayout(&layoutright);
QHBoxLayout layoutbottom;
QPushButton buttonapply("Apply");
QPushButton buttoncancel("Cancel");
layoutbottom.addWidget(&buttonapply);
layoutbottom.addWidget(&buttoncancel);
layout.addLayout(&layouttop);
layout.addLayout(&layoutmiddle);
layout.addLayout(&layoutbottom);
window.setLayout(&layout);
window.show();
/* ******************** First Window ******************** */
/* ******************** Second Window ******************** */
QWidget windowed;
QVBoxLayout layouted;
windowed.setWindowTitle("Session");
windowed.setWindowIcon(QIcon(":/Images/Images/Bouclier.png"));
windowed.setFixedSize(450, 400);
QHBoxLayout layouttoped;
QLabel labeltoped("Nom de la session :");
QLineEdit lineedittoped;
layouttoped.addWidget(&labeltoped);
layouttoped.addWidget(&lineedittoped);
QHBoxLayout layoutmiddled;
QPushButton buttonnexted;
QPushButton buttonprevioused;
QPushButton buttonetced("...");
QString file;
QLineEdit lined0;
QLineEdit lined1;
QLineEdit lined2;
QLineEdit lined3;
QLineEdit lined4;
QLineEdit lined5;
QLineEdit lined6;
QLineEdit lined7;
QLineEdit lined8;
QLineEdit lined9;
QComboBox box;
QLabel label("Durée :");
QVBoxLayout layoutlefted;
layoutlefted.addWidget(&buttonnexted);
buttonnexted.setIcon(QIcon(":/Images/Images/Haut.png"));
layoutlefted.addWidget(&buttonprevioused);
buttonprevioused.setIcon(QIcon(":/Images/Images/Bas.png"));
QVBoxLayout layoutcentered;
layoutcentered.addWidget(&lined0);
layoutcentered.addWidget(&lined1);
layoutcentered.addWidget(&lined2);
layoutcentered.addWidget(&lined3);
layoutcentered.addWidget(&lined4);
layoutcentered.addWidget(&lined5);
layoutcentered.addWidget(&lined6);
layoutcentered.addWidget(&lined7);
layoutcentered.addWidget(&lined8);
layoutcentered.addWidget(&lined9);
lined0.setReadOnly(true);
lined1.setReadOnly(true);
lined2.setReadOnly(true);
lined3.setReadOnly(true);
lined4.setReadOnly(true);
lined5.setReadOnly(true);
lined6.setReadOnly(true);
lined7.setReadOnly(true);
lined8.setReadOnly(true);
lined9.setReadOnly(true);
QVBoxLayout layoutrighted;
layoutrighted.addWidget(&buttonetced);
QVBoxLayout layoutmore;
QHBoxLayout layoutmored;
layoutmored.addWidget(&label);
layoutmored.addWidget(&box);
box.addItem("30");
box.addItem("60");
layoutmore.addLayout(&layoutmored);
layoutmiddled.addLayout(&layoutlefted);
layoutmiddled.addLayout(&layoutcentered);
layoutmiddled.addLayout(&layoutrighted);
layoutmiddled.addLayout(&layoutmore);
QHBoxLayout layoutbottomed;
QPushButton buttonapplyed("Apply");
QPushButton buttoncanceled("Cancel");
layoutbottomed.addWidget(&buttonapplyed);
layoutbottomed.addWidget(&buttoncanceled);
layouted.addLayout(&layouttoped);
layouted.addLayout(&layoutmiddled);
layouted.addLayout(&layoutbottomed);
windowed.setLayout(&layouted);
/* ******************** Second Window ******************** */
/* ******************** Actions First Window ******************** */
QObject::connect(&buttonetc, &QPushButton::clicked, &windowed, &QWidget::show);
/* ******************** Actions First Window ******************** */
/* ******************** Actions Second Window ******************** */
QObject::connect(&buttonetced, &QPushButton::clicked, [&windowed, &file] {file = QFileDialog::getOpenFileName(&windowed, QObject::tr("Sélectionner un fichier son ..."), "C:/", QObject::tr("Audio (*.mp3)"));});
lined0.setText(Qstring(file));
/* ******************** Actions Second Window ******************** */
return program.exec();
}
也许您可以尝试在一个窗口中发出文件名的地址,然后通过插槽功能在第二个窗口中接收该地址
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.