Bonjour,

J'aimerais créer une fonction pour enregistrer un projet.
Ce projet serait un dossier comprenant d'autres dossier ainsi qu'un fichier projet (comme sur Visual Studio ou Qt Creator). Je m'explique en vous montrant ma class.
Fichier projet.h:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
 
#ifndef PROJECT_H
#define PROJECT_H
 
#include <QDir>
#include <QMultiMap>
 
 
class Project
{
 
public:
    static bool isValidProject( QString &path );
    static Project* openProject( QString &path );
    static Project* createProject( QString &path );
    void save();
    void refresh();
 
    QList<QString> getDataByExtention(QString extention);
    QDir& path();
 
private:
    Project( QDir& path );
    QDir _path;
    QMultiMap<QString,QString> _metaProjData;
    QString _projectName;
    QString _projectDescription;
};
 
#endif // PROJECT_H
Fichier projet.cpp:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include "project.h"
#include <QFileDialog>
 
 
Project *Project::openProject(QString &path)
{
    QDir dir;
    if(!dir.exists(path+"//ivt_project.ivp"))
    {
        return NULL;
    }
    dir.cd(path);
    return new Project(dir);
 
}
 
Project* Project::createProject(QString &path)
{
    QDir dir;
 
    if((!dir.exists(path))&&dir.mkpath(path))
    {
        dir.cd(path);
        dir.mkdir("Actions");
        dir.mkdir("Movies");
        dir.mkdir("Data");
        QFile descriptor("ivt_project.ivp");
        descriptor.open( QIODevice::WriteOnly );
 
        QFile actionfile(path+"/Actions/actionfile.act");
        actionfile.open( QIODevice::WriteOnly );
        QFile moviefile(path+"/Movies/moviefile.avi");
        moviefile.open( QIODevice::WriteOnly );
        QFile datafile (path+"/Data/datafile.txt");
        datafile.open( QIODevice::WriteOnly );
 
 
        return new Project(dir);
    }
    return NULL;
}
 
Project::Project(QDir &path)
{
    _path = path;
}
 
void save()
{     
    //QString ProjectName = QFileDialog::getSaveFileName(/*this,*/"Save Project", "", "Project files(*.ivp);;All Files (*)");
 
 
    //just save project all rest including in the project (createproject)
    //save all actions file
    //save all movies
    //save all data
    //save descriptor
 
   /* QString filename="actionfile.act";
    if (filename.isEmpty())
        return;
    else{
        QFile file(filename);
        if(!file.open(QIODevice::WriteOnly)){
            return;
        }
        QDataStream out(&file);
        out << file;
        }
*/
}
J'espère que c'est clair. J'ai essayé quelques trucs comme vous pouvez le voir. Quelqu'un saurait-il comment faire svp?

Cordialement.

klelu