IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Qt Discussion :

Problème de return


Sujet :

Qt

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éclairé
    Homme Profil pro
    amateur
    Inscrit en
    Octobre 2007
    Messages
    731
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations professionnelles :
    Activité : amateur

    Informations forums :
    Inscription : Octobre 2007
    Messages : 731
    Par défaut Problème de return
    Bonjour,

    J'ai ma fonction QtCopy qui renvoit un qint64 ( la taille en octet d'un fichier que je cumule au fur et à mesure des copies pour avoir l'anvancement dans la QProgressBar).
    Le problème est que lorsque je fais un return sur la variable qui stocke cette donnée et bien ma fonction de copy ne d'effectue plus.




    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
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    // BIBLIOTHEQUES //////////////////////////////////////////////////////////////
    #include <QApplication>
    #include <QDirIterator>
    #include <QWidget>
    #include <QPushButton>
    #include <QLabel>
    #include <QProgressBar>
    #include <QFile>
    #include <QString>
    #include <QFileDialog>
    #include <QObject>
    #include <QStringList>
    #include <windows.h>
    #include "fenetre.h"
     
    // CONSTANTES //////////////////////////////////////////////////////////////////
    #define WIDTH 75
    #define SPACE 20
     
    // PROTOTYPES //////////////////////////////////////////////////////////////////
    qint64 QtCopy( int X, int Y, qint64 Progress, QString QCopySize, char *SrcPath, char *TarPath, QLabel *PrintFileNumbers, QLabel *PrintSrcPath, QLabel *PrintTarPath, QLabel *PrintFileSize, QLabel *PrintFileName, QLabel *PrintSizes);
    qint64 FolderSize(char *path);
     
    // CLASSE FENETRE //////////////////////////////////////////////////////////////
    MaFenetre::MaFenetre() : QWidget()
    {
     
    	int X = (int)(0.7*GetSystemMetrics(SM_CXSCREEN)); /* Largeur de la fenêtre */
    	int Y = (int)(0.4*GetSystemMetrics(SM_CYSCREEN)); /* Longueur de la fenêtre */
     
    	setFixedSize(X, Y); // On fixe définitivement la FolderSize de la fenêtre
     
        char S_XS[999], S_XS2[999], S_D2A[999], S_EASY[999], S_ALCATEL[999], S_VOCALD6[999], S_SAUVMATRA[999], S_MATRAPARALLELE[999]; // Chemin des dossiers sources 
        char D_XS[999], D_XS2[999], D_D2A[999], D_EASY[999], D_ALCATEL[999], D_VOCALD6[999], D_SAUVMATRA[999], D_MATRAPARALLELE[999]; // Chemin des dossiers cibles
     
    	/* On récupère ces chemin dans setup.ini */
    	GetPrivateProfileStringA("section", "S_XS"            , "", S_XS            , 999, ".//setup.ini");
    	GetPrivateProfileStringA("section", "S_XS2"           , "", S_XS2           , 999, ".//setup.ini");
    	GetPrivateProfileStringA("section", "S_D2A"           , "", S_D2A           , 999, ".//setup.ini");
    	GetPrivateProfileStringA("section", "S_EASY"          , "", S_EASY          , 999, ".//setup.ini");
    	GetPrivateProfileStringA("section", "S_ALCATEL"       , "", S_ALCATEL       , 999, ".//setup.ini");
    	GetPrivateProfileStringA("section", "S_VOCALD6"       , "", S_VOCALD6       , 999, ".//setup.ini");
    	GetPrivateProfileStringA("section", "S_SAUVMATRA"     , "", S_SAUVMATRA     , 999, ".//setup.ini");
    	GetPrivateProfileStringA("section", "S_MATRAPARALLELE", "", S_MATRAPARALLELE, 999, ".//setup.ini");
    	GetPrivateProfileStringA("section", "D_XS"            , "", D_XS            , 999, ".//setup.ini");
    	GetPrivateProfileStringA("section", "D_XS2"           , "", D_XS2           , 999, ".//setup.ini");
    	GetPrivateProfileStringA("section", "D_D2A"           , "", D_D2A           , 999, ".//setup.ini");
    	GetPrivateProfileStringA("section", "D_EASY"          , "", D_EASY          , 999, ".//setup.ini");
    	GetPrivateProfileStringA("section", "D_ALCATEL"       , "", D_ALCATEL       , 999, ".//setup.ini");
    	GetPrivateProfileStringA("section", "D_VOCALD6"       , "", D_VOCALD6       , 999, ".//setup.ini");
    	GetPrivateProfileStringA("section", "D_SAUVMATRA"     , "", D_SAUVMATRA     , 999, ".//setup.ini");
    	GetPrivateProfileStringA("section", "D_MATRAPARALLELE", "", D_MATRAPARALLELE, 999, ".//setup.ini");
     
    	/* Création des objets */
    	Title                     = new QLabel      ("<SMALL><strong>SAUVEGARDE AUTOMATIQUES DES DONNEÉS</strong></SMALL>", this);
        ButtonOk                  = new QPushButton ("  OK",                                                                this);
    	ButtonStop                = new QPushButton ("STOP",                                                                this);
    	PrintSizes                = new QLabel      (                                                                       this);
    	PrintSrcPath              = new QLabel      (                                                                       this);
    	PrintTarPath              = new QLabel      (                                                                       this);
    	PrintFileSize             = new QLabel      (                                                                       this);
    	PrintFileName             = new QLabel      (                                                                       this);
    	PrintFileNumbers          = new QLabel      (                                                                       this);
        QProgressBar *ProgressBar = new QProgressBar(                                                                       this);
     
    	/* Attributs sur les objets */ 
        Title       -> move       ( (X - Title->minimumSizeHint().width())/2, 0.05*Y                      );
    	ButtonOk    -> setGeometry( (int)((X-(2*WIDTH+SPACE))/2+WIDTH+SPACE),  (int)(0.9*Y), WIDTH, SPACE );
    	ButtonStop  -> setGeometry( (int)((X-(2*WIDTH+SPACE))/2            ),  (int)(0.9*Y), WIDTH, SPACE );
        ProgressBar -> setGeometry( 0.125*X, 0.1*Y, 0.75*X, 0.075*Y                                       );
    	ProgressBar -> setRange   ( 0, 100                                                                ); 
    	ProgressBar -> setValue   ( 0                                                                     );
     
    	qint64  CopySize  = FolderSize(S_XS)+FolderSize(S_XS2)+FolderSize(S_D2A)+FolderSize(S_EASY)+FolderSize(S_ALCATEL)+FolderSize(S_VOCALD6)+FolderSize(S_SAUVMATRA)+FolderSize(S_MATRAPARALLELE); /* On calcule le volume de donnée que la copie va engendrer */
        QString QCopySize = QString::number(CopySize); /* On convertit le volume de donnée à copier en QString */
     
    	qint64 Progress;
     
    	/* Copie des dossiers */
        Progress    =  QtCopy   ( X, Y,        0, QCopySize, S_XS            , D_XS            , PrintFileNumbers, PrintSrcPath, PrintTarPath, PrintFileSize, PrintFileName, PrintSizes);
    	ProgressBar -> setValue ( Progress                                                                                                                           );
        Progress    =  QtCopy   ( X, Y, Progress, QCopySize, S_XS2           , D_XS2           , PrintFileNumbers, PrintSrcPath, PrintTarPath, PrintFileSize, PrintFileName, PrintSizes);
    	ProgressBar -> setValue ( Progress                                                                                                                           );
        Progress    =  QtCopy   ( X, Y, Progress, QCopySize, S_D2A           , D_D2A           , PrintFileNumbers, PrintSrcPath, PrintTarPath, PrintFileSize, PrintFileName, PrintSizes);
        ProgressBar -> setValue ( Progress                                                                                                                           );
    	Progress    =  QtCopy   ( X, Y, Progress, QCopySize, S_EASY          , D_EASY          , PrintFileNumbers, PrintSrcPath, PrintTarPath, PrintFileSize, PrintFileName, PrintSizes);
    	ProgressBar -> setValue ( Progress                                                                                                                           );
        Progress    =  QtCopy   ( X, Y, Progress, QCopySize, S_ALCATEL       , D_ALCATEL       , PrintFileNumbers, PrintSrcPath, PrintTarPath, PrintFileSize, PrintFileName, PrintSizes);
    	ProgressBar -> setValue ( Progress                                                                                                                           );
        Progress    =  QtCopy   ( X, Y, Progress, QCopySize, S_VOCALD6       , D_VOCALD6       , PrintFileNumbers, PrintSrcPath, PrintTarPath, PrintFileSize, PrintFileName, PrintSizes);
    	ProgressBar -> setValue ( Progress                                                                                                                           );
        Progress    =  QtCopy   ( X, Y, Progress, QCopySize, S_SAUVMATRA     , D_SAUVMATRA     , PrintFileNumbers, PrintSrcPath, PrintTarPath, PrintFileSize, PrintFileName, PrintSizes);
    	ProgressBar -> setValue ( Progress                                                                                                                           );
        Progress    =  QtCopy   ( X, Y, Progress, QCopySize, S_MATRAPARALLELE, D_MATRAPARALLELE, PrintFileNumbers, PrintSrcPath, PrintTarPath, PrintFileSize, PrintFileName, PrintSizes);
        ProgressBar -> setValue ( Progress                                                                                                                                );
     
        /* Signaux */
    	QObject::connect(ButtonStop, SIGNAL(clicked()) , qApp, SLOT( aboutQt() ) );
    	QObject::connect(  ButtonOk, SIGNAL(clicked()) , qApp, SLOT( quit   () ) );
    }
     
    // FUNCTIONS ///////////////////////////////////////////////////////////////////
    qint64 QtCopy( int X, int Y, qint64 Progress, QString QCopySize, char *SrcPath, char *TarPath, QLabel *PrintFileNumbers, QLabel *PrintSrcPath, QLabel *PrintTarPath, QLabel *PrintFileSize, QLabel *PrintFileName, QLabel *PrintSizes)
    {
     
        QString Src = QString(SrcPath); /* Convertion de la variable char en QString ( répertoire source ) */
        QString Tar = QString(TarPath); /* Convertion de la variable char en QString ( répertoire cible ) */
     
        QDir::setCurrent(Src); /* On se place dans le repertoire source */
    	QDir  dirSource (Src); /**/
     
            QStringList Filter; /* On déclare un filtre sur les extentions de fichiers */
    	Filter << "*.*"; /* On récupère tous les types de fichier */
    	dirSource.setNameFilters(Filter); /* On enregistre les noms de fichiers dans le filtre */
     
    	int i;
    	int FileNumbers = dirSource.count(); /* On récupère le nombre de fichiers à copier */
    	for ( i=0 ; i < FileNumbers ; i++ )
    	{
    		QString SrcPath; /* Variable QString pour stocker le chemin complet du fichier source */
    		QString TarPath; /* Variable QString pour stocker le chemin complet du fichier cible */
     
    		QString FileName = dirSource.entryList(Filter).at(i); /* On récupère chaque nom de fichier contenu dans le filtre grâce à la boucle */
    		if (FileName != "." && FileName != ".." ) /* On controle que le fichier n'est pas le repertoire parent ou le répertoire courant */
    		{
     
    			SrcPath = Src + FileName; /* On concatène le chemin du fichier source avec son nom */
    			TarPath = Tar + FileName; /* On concatène le chemin du fichier cible avec son nom */
     
                QString QFileNumbers=QString::number(FileNumbers-2);
    		    QFileInfo fi(SrcPath); /* On récupère des informations sur le fichier */
    			QString   FileSize     = QString::number(fi.size()/1024       ); /* On récupère la FolderSize de ce fichier */
    			QString   QProgress    = QString::number(Progress/(1024*1024));
     
                /* On place les QLabel dans la fenêtre */
                PrintSizes       -> move( (X - PrintSizes       -> minimumSizeHint().width())/2, 0.25*Y );
                PrintSrcPath     -> move( (X - PrintSrcPath     -> minimumSizeHint().width())/2, 0.35*Y );
    			PrintTarPath     -> move( (X - PrintTarPath     -> minimumSizeHint().width())/2, 0.45*Y );
    			PrintFileName    -> move( (X - PrintFileName    -> minimumSizeHint().width())/2, 0.55*Y );
                PrintFileSize    -> move( (X - PrintFileSize    -> minimumSizeHint().width())/2, 0.65*Y );
                PrintFileNumbers -> move( (X - PrintFileNumbers -> minimumSizeHint().width())/2, 0.75*Y );
     
    			// On met à jour leur affichage //
    		    PrintSrcPath     -> setText("<small><strong>SOURCE      :</strong></small> " + SrcPath          );
    			PrintTarPath     -> setText("<small><strong>DESTINATION :</strong></small> " + TarPath          );
                PrintFileName    -> setText("<small><strong>NOM DU FICHIER    :</strong></small> " + FileName         );
                PrintFileSize    -> setText("<small><strong>TAILLE      :</strong></small> " + FileSize  + " Ko");
                PrintSizes       -> setText("<small><strong>TRANSFERT   :</strong></small> " + QProgress +"/"+ QCopySize + " Mo");
                PrintFileNumbers -> setText("<small><strong>NOMBRE DE FICHIERS DANS LE DOSSIER   :</strong></small> " + QFileNumbers);
     
    			qint64 CurrentSize = fi.size();
    			CurrentSize = Progress + CurrentSize;
     			QString QCurrentSize = QString::number(CurrentSize/(1024*1024));
    			PrintSizes    -> setText("<small><strong>TRANSFERT   :</strong></small> " + QCurrentSize+"/"+QCopySize + " Mo");
     
                QFile file(SrcPath); /* On déclare le fichier de chemin SrcPath */
    			file.copy(TarPath); /* On effectue la copie de ce fichier */
     
                return CurrentSize;
    		}
    	}
    }
     
    ////////////////////////////////////////////////////////////////////////////////
    qint64 FolderSize(char *path)
    {
     
    	QString Src = QString(path); /* Convertion de la variable char en QString ( répertoire source ) */
     
        QDir::setCurrent(path); /* On se place dans le repertoire source */
    	QDir  dirSource (path); /**/
     
            QStringList Filter; /* On déclare un filtre sur les extentions de fichiers */
    	Filter << "*.*"; /* On récupère tous les types de fichier */
    	dirSource.setNameFilters(Filter); /* On enregistre les noms de fichiers dans le filtre */
     
        qint64 FolderSize=0;
     
        int i;
    	int FileNumbers = dirSource.count(); /* On récupère le nombre de fichiers à copier */
    	for ( i=0 ; i < FileNumbers ; i++ )
    	{
    		QString SrcPath; /* Variable QString pour stocker le chemin complet du fichier source */
     
    		QString FileName = dirSource.entryList(Filter).at(i); /* On récupère chaque nom de fichier contenu dans le filtre grâce à la boucle */
    		if (FileName != "." && FileName != ".." ) /* On controle que le fichier n'est pas le repertoire parent ou le répertoire courant */
    		{
    			SrcPath = Src + FileName; /* On concatène le chemin du fichier source avec son nom */
     
    		    QFileInfo fi(SrcPath); /* On récupère des informations sur le fichier */
     
    			qint64 FileSize   = fi.size()/(1024*1024); /* On récupère la FolderSize en Mo du fichier */
    			       FolderSize = FolderSize+FileSize; /* On l'ajoute à la taille du dossier au fur et à mesure que la boucle s'incrèmente */
    		}
    	}
     
    	return FolderSize; /* On renvoit l'information */
     
    }
    Merci d'avance

  2. #2
    Membre chevronné
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Mai 2006
    Messages
    507
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Pas de Calais (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : Communication - Médias

    Informations forums :
    Inscription : Mai 2006
    Messages : 507
    Par défaut
    Bonjour,

    Citation Envoyé par darkwall_37 Voir le message
    Bonjour,

    J'ai ma fonction QtCopy qui renvoit un qint64 ( la taille en octet d'un fichier que je cumule au fur et à mesure des copies pour avoir l'anvancement dans la QProgressBar).
    Le problème est que lorsque je fais un return sur la variable qui stocke cette donnée et bien ma fonction de copy ne d'effectue plus.
    J'ai pas regardé en détail le code, mais ça me parait plutôt logique... Si tu fais un "return" ta fonction retourne la valeur et s'arrête... C'est le principe du return !
    Donc si tu veux voir la progression de ta variable il faut faire autrement.

    Par exemple tu peux mettre ta fonction "QtCopy" dans un QThread, et au lieu de faire des return, tu peux émettre un signal avec la valeur de ta variable. En branchant ce signal (sans doute indirectement) sur ta QProgressBar, tu verras progresser cette dernière.

  3. #3
    Membre éclairé
    Homme Profil pro
    amateur
    Inscrit en
    Octobre 2007
    Messages
    731
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations professionnelles :
    Activité : amateur

    Informations forums :
    Inscription : Octobre 2007
    Messages : 731
    Par défaut
    Je ne sais pas me servir des QThread. J'en aurais besoin de toute façon pour faire afficher la fenêtre en même temps que la copie a lieu.

    Je vais essayer de faire un truck mais j'y comprends pas grand chose à la FAQ.

  4. #4
    Rédacteur

    Inscrit en
    Novembre 2006
    Messages
    1 272
    Détails du profil
    Informations forums :
    Inscription : Novembre 2006
    Messages : 1 272
    Par défaut
    Lien de base sur les Thread avec Qt ici.
    Tu as aussi la FAQ mais d'apres ce que tu dis elle t'aide pas beaucoup. Sinon tu as encore des exemples dans le SDK Qt.
    Vous voulez participer aux Tutoriels, FAQ ou Traductions et faire partie de l'équipe Qt de Developpez.
    N'hésitez pas à me contacter par MP.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Problème: "Query returns more than one row"
    Par ctobini dans le forum Requêtes
    Réponses: 1
    Dernier message: 27/09/2007, 11h48
  2. Problème de return avec l'OO
    Par Jasmine80 dans le forum Langage
    Réponses: 2
    Dernier message: 25/05/2007, 16h25
  3. Problème de return
    Par Cassius dans le forum Langage
    Réponses: 3
    Dernier message: 31/05/2006, 14h56
  4. Problème avec return
    Par Rémiz dans le forum Général JavaScript
    Réponses: 16
    Dernier message: 25/08/2005, 17h15
  5. [FLASH MX2004] [AS2] Problème de return
    Par bolo dans le forum ActionScript 1 & ActionScript 2
    Réponses: 6
    Dernier message: 08/04/2005, 08h58

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo