Hi,
First of all, I am a beginner in the QT word so sorry if what I wrote is bad.
I would like to create a directory at the beginning of the application. The directory name can vary
depending on the situation.
Then I would like to save future files created in a class named fenetre into this directory.
For that:
I create a Class named CreateDirectory , Its constructor creates the directory that will be used
later and a parameter of this class (QString repertoire) contains the directory name.
I create a class named fenetre and declare ‘friend class CreateDirectory;’ in its header.
I create an objet of the class CreateDirectory named rep in the main.cpp And create a class-fenetre
objet with rep as an argument .
Please find below what I have done so far.
Clicking the button ‘next’ has no effect.
Could you help me out with this problem.
Thank you in advance.
//main.cpp
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
CreateDirectory *rep= new CreateDirectory;
rep->show();
fenetre h(rep);
h.show();
return a.exec();
}
//CreateDirectory.cpp
CreateDirectory::CreateDirectory(){
int n=1;
QDir lDir;
QString dossier="repertoire";
while (true){
dossier = "repertoire"+ qApp->tr("-%1").arg(n);
if ( !lDir.exists ( dossier ))
{
lDir.mkdir(dossier);
break;
}
else
n += 1;
}
//-----------------------
repertoire=dossier+"\\";
}
fenetre::fenetre(CreateDirectory *rep){
DirectoryDeTravail=rep.repertoire;
QPushButton *quitter= new QPushButton("Quitter", this);
connect(quitter,SIGNAL(clicked()),qApp,SLOT(quit()));
QPushButton *next= new QPushButton("Next", this);
connect(next,SIGNAL(clicked( CreateDirectory,QLineEdit
)),this,SLOT(monslot(CreateDirectory,QLineEdit)));
line= new QLineEdit(this); // a number
}
void fenetre::monslot(CreateDirectory *rep, QlineEdit * line)
{
this->hide();
QFile output(QString("%1/nom%2.txt").arg(DirectoryDeTravail).arg(line->text()));
fenetre h(rep);
h->show();
}
↧