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

Threads & Processus C++ Discussion :

Probléme d'enumération dans une classe


Sujet :

Threads & Processus C++

  1. #1
    Membre éclairé
    Avatar de alpha_one_x86
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Décembre 2006
    Messages
    411
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Somme (Picardie)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Décembre 2006
    Messages : 411
    Par défaut Probléme d'enumération dans une classe
    Bonjour,
    Voila un extrait de mon code:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    class copyThread : public QThread
    {
    ...
    public:
    	enum currentStat {
    	Stopped,
    	Paused,
    	Running
    	};
    	copyThread::currentStat theCurrentStat;	///< The current stat
    };
    Et voila l'erreur.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    CopyThread.h:130: error: 'currentStat' in class 'copyThread' does not name a type
    Pour moi c'est bon, ou est mon erreur?

  2. #2
    Expert éminent
    Avatar de koala01
    Homme Profil pro
    aucun
    Inscrit en
    Octobre 2004
    Messages
    11 633
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 53
    Localisation : Belgique

    Informations professionnelles :
    Activité : aucun

    Informations forums :
    Inscription : Octobre 2004
    Messages : 11 633
    Par défaut
    Salut,
    Citation Envoyé par alpha_one_x86 Voir le message
    Bonjour,
    Voila un extrait de mon code:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    class copyThread : public QThread
    {
    ...
    public:
    	enum currentStat {
    	Stopped,
    	Paused,
    	Running
    	};
    	copyThread::currentStat theCurrentStat;	///< The current stat
    };
    Et voila l'erreur.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    CopyThread.h:130: error: 'currentStat' in class 'copyThread' does not name a type
    Pour moi c'est bon, ou est mon erreur?
    L'erreur vient du fait que tu donne, à l'intérieur de la classe, un chemin faisant appel à copyThread::.

    Ce qui fait , comme tu est à l'intérieur de copyThread, que le compilateur cherche quelque chose qui, vue de l'extérieur de la classe devrait se trouver dans copyThread::copyThread et qui s'appelle currentStat

    La solution est donc toute simple: à l'intérieur de la classe, tu peux simplement utiliser currentStat.

    Par contre, dés que tu n'est plus dans la classe (ou dans l'une des fonctions membre de la classe), si tu veux disposer d'une variable de type currentStat, il faudra effectivement dire que ce type est imbriqué dans copyThread sous la forme de copyThread::currentStat
    A méditer: La solution la plus simple est toujours la moins compliquée
    Ce qui se conçoit bien s'énonce clairement, et les mots pour le dire vous viennent aisément. Nicolas Boileau
    Compiler Gcc sous windows avec MinGW
    Coder efficacement en C++ : dans les bacs le 17 février 2014
    mon tout nouveau blog

  3. #3
    Membre éclairé
    Avatar de alpha_one_x86
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Décembre 2006
    Messages
    411
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Somme (Picardie)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Décembre 2006
    Messages : 411
    Par défaut
    Avec:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    currentStat theCurrentStat;	///< The current stat
    J'ai:
    CopyThread.h:130: error: 'currentStat' does not name a type
    Voila mon code complet:
    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
    /***************************************************************************
                                      CopyThread.h
                                  -------------------
     
         Begin        : Fri Dec 21 2007 22:42 alpha_one_x86
         Project      : Ultracopier
         Email        : alpha.super-one@laposte.net
         Note         : See README for copyright and developer
         Target       : Define the class of the copyThread
     
    ****************************************************************************/
     
    #include "env.h"
     
    #ifndef COPY_THREAD_H
    #define COPY_THREAD_H
     
    #include <QThread>
    #include <QFile>
    #include <QDir>
    #include <QWaitCondition>
    #include <QMutex>
    #include <QTimer>
    #include <QTime>
    #include <QCryptographicHash>
    #include <QByteArray>
     
    /** \brief Thread for do the copy.
     
    This thread do the copy, it store the permanently options, and use shared memory for get and set the variable, and use signal/slot for the events.
    */
    class copyThread : public QThread
    {
    	Q_OBJECT
    public slots:
    	//add one entry to source dir list
    	void addEntryToDirList(const QString& theDir);
    	//add one entry to empty dir destination list
    	void addEntryToEmptyDestinationDirList(const QString& theDir);
     
    	//set the copy info and options before runing
    	void setRightCopy(const int doRightCopy);
    	//set keep date
    	void setKeepDate(const int);
    	//set the current max speed in KB/s
    	void setMaxSpeed(int tempMaxSpeed);
    	//set if in copy or move mode
    	void setMovingMode(const bool setMove);
    	//set block size
    	bool setBlockSize(const int block=64);
    	//set prealoc file size
    	void setPreallocateFileSize(const bool prealloc);
     
    	//add item to list
    	void addToList(const QString& source,const QString& destination);
    	//pause the copy
    	void pauseCopy();
    	//resume the copy
    	void resumeCopy();
    	//stop the current copy
    	void stopTheCopy();
     
    	//return the progression percent
    	int theProgressionPercent(const int max=100);
    	//get copy speed in byte per second
    	qint64 getCopySpeed();
     
    public:
    	enum currentStat {
    			Stopped,
    			Paused,
    			Running
    		};
    	copyThread();
    	~copyThread();
    	/// \brief set action on file exist
    	void fileExistsAction(int action);
    	/// \brief set action on error
    	void errorAction(int action);
            /// \brief get current file copied as String as Name and size
            QString getCurrentFileCopied();
            /// \brief lenght of copy list
            qint64 lenghtOfCopyList();
    	/// \brief return the statut
    	currentStat currentStat();
    signals:
    	/// \brief error on flush, with the error subject
    	void errorOnFlush(QString);
    	/// \brief error on file, bouton enable, file path, error message
    	void errorOnFile(int,QString,QString);
    	/// \brief signal emited when file is same
    	void fileIsSame(QString);
    	/// \brief signal emited when file exists, Source, Destination
    	void fileIsExists(QString,QString);
    protected:
    	void run();
    	void stop();
    private:
    	// Remove all the empty source folder
    	bool removeAllFolderEmpty(const QString& TheDir);
    	//try open file in special mode
            bool tryOpenFileInSpecialMode(QFile *theFile,QIODevice::OpenMode theModeShouldBeUsed);
    	//remove source folder and create destination folder
    	bool flush();
     
    	volatile bool stopped;
    	volatile bool waitInPause;	///< Wait in pause the thread
    	volatile bool stopIt;		///< For store the stop query
    	QString errorMessageInCopy;	///< The message error
    	qint64 totalCopiedSize;		///< The copied, read or manipuled size
    	qint64 previousSizeReturned;	///< Previous size returned
    	int maxSpeed;			///< The max speed in MB/s, 0 for no limit
    	bool RightCopy;			///< Do rights copy
    	bool movingMode;		///< Set if is in moving mode
    	bool tooLateForWait;		///< Flag for know if it's too late for wait the next timer time out
    	bool preallocation;		///< Flag for know if need preallocation
    	bool keepDate;			///< For keep date file
    	QTime intervalCopySpeed;	///< For detect the interval beteew 2 copy speed mesurement
    	int actionAfterUnlock;		///< For action after unlock the mutex
            QList<QString> sourceDirList;	///< List of source dir for delete it in moving mode
    	QList<QString> emptyDestDir;	///< List of empty destination should be created
    	QTimer clockForTheCopySpeed;	///< For the speed throttling
    	QWaitCondition waitTimerIsEnd;	///< For wait a event for speed limitation
    	QWaitCondition controlMutex;	///< For stop/pause/resume copy
    	QMutex mutexWait;		///< For use the mutex to speed limitation
    	QMutex mutexWaitControl;	///< For use the mutex to control the copy
    	int MultForBigSpeed;		///< Multiple for count the number of block needed
    	int numberOfBlockCopied;	///< Multiple for count the number of block copied
    	int blockSizeCurrent;		///< The current size of the buffer
    	currentStat theCurrentStat;	///< The current stat
    	QFile *sourceFile;		///< For have global copie progression
    	QFile *destinationFile;		///< For have global copie progression
    	// for copy list
    	volatile QList<QList<QString> > theCopyList;
    private slots:
    	void timeOfTheBlockCopyFinished();
    };
     
    #endif
    Et mon corp de fonction:
    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
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    /***************************************************************************
                                    CopyThread.cpp
                                    -------------------
     
         Begin      : Fri Dec 21 2007 22:48 alpha_one_x86
         Project    : Ultracopier
         Email      : alpha.super-one@laposte.net
         Note        : See README for copyright and developer
         Target      : Define the class of the copy threads
     
    ****************************************************************************/
     
    #include "env.h"
     
    #include "CopyThread.h"
     
    /*! \todo checksun while copy
      \todo remove empty source folder in moving mode
      \todo support folder empty in copy and move mode
      \warning check empty dest folder is created
      \todo call copyThread::flush() at the end of copy
      \todo adaptative total size
      \todo, when skip remove destination
      */
     
    /*! \brief Initialise the copy thread
    */
    copyThread::copyThread()
    {
    	RightCopy=false;
    	FileName="";
    	maxSpeed=0;
    	connect(&clockForTheCopySpeed, SIGNAL(timeout()), this, SLOT(timeOfTheBlockCopyFinished()));
    	stopped = true;
    	movingMode=false;
    	blockSizeCurrent=64;
    	tooLateForWait=false;
    	preallocation=false;
    	previousSize=0;
    	intervalCopySpeed.start();
    	keepDate=false;
    	waitInPause=false;
    	theCurrentStat=Stopped;
    	sourceFile=new QFile("");							///< Pointer on the source file
    	destinationFile=new QFile("");
    	totalCopiedSize=0;
    	previousSizeReturned=0;
    }
     
    /// \brief set action on file exist
    void copyThread::fileExistsAction(int action)
    {
    	actionAfterUnlock=action;
    	resumeCopy();
    }
     
    /// \brief set action on error
    void copyThread::errorAction(int action)
    {
    	actionAfterUnlock=action;
    	resumeCopy();
    }
     
    //pause the copy
    void copyThread::pauseCopy()
    {
    	if(currentStat!=copyThread::Paused)
    		waitInPause=true;
    	else
    	{
    		DEBUGCONSOLE(10,"copyThread::pauseCopy","Copy thread already in pause");
    	}
    }
     
    //resume the copy
    void copyThread::resumeCopy()
    {
    	if(currentStat==copyThread::Paused)
    	{
    		controlMutex.wakeAll();
    		waitInPause=false;
    	}
    	else
    	{
    		DEBUGCONSOLE(10,"copyThread::resumeCopy","Copy thread not in pause");
    	}
    }
     
    /** \brief set block size
    \param block the new block size
    \return Return true if succes */
    bool copyThread::setBlockSize(const int block)
    {
    	DEBUGCONSOLE(50,"copyThread::setBlockSize","Set new block size: "+QString::number(block));
    	if(block<1 || block>16384)
    	{
    		blockSizeCurrent=block*1024;
    		//set the new max speed because the timer have changed
    		setMaxSpeed(maxSpeed);
    		return true;
    	}
    	else
    		return false;
    }
     
    /** \brief set keep date
    \param value The value setted */
    void copyThread::setKeepDate(const int value)
    {
    	keepDate=value;
    }
     
    /** \brief Add item to list
    \param source The source
    \param destination The folder or file destination
    */
    void copyThread::addToList(const QString& source,const QString& destination)
    {
    	QList<QString> oneEntry;
    	oneEntry.append(source);
    	oneEntry.append(destination);
    	theCopyList.append(oneEntry);
    }
     
    /** \brief return the progression percent
    \param max the return value it should be beteen 0 and max value
    \return the file progression
    */
    int copyThread::theProgressionPercent(const int max)
    {
    	if(!sourceFile->isOpen() || !destinationFile->isOpen())
    		return 0;
    	else
    		return (int)((((double)(destinationFile->pos()))/(sourceFile->size()))*max);
    }
     
    /** \brief get copy speed in byte per second
    \return Return the speed in byte per second */
    qint64 copyThread::getCopySpeed()
    {
    	//for have fixed value (not change durring copy)
    	qint64 totalCopiedSize=this->totalCopiedSize;
    	//for calcul copied size
    	qint64 returnedValue=totalCopiedSize-previousSizeReturned;
    	if(returnedValue==0)
    		return 0;
    	//get elapsed time
    	int timeFromNextRestart=intervalCopySpeed.elapsed();
    	if(timeFromNextRestart<=0)
    		return -1;
    	else
    	{
    		returnedValue=(returnedValue*1000/timeFromNextRestart);
    		intervalCopySpeed.restart();
    	}
    	previousSizeReturned=totalCopiedSize;
    	return returnedValue;
    }
     
    /** \brief set prealoc file size
    \param prealloc True if should be prealloc */
    void copyThread::setPreallocateFileSize(const bool prealloc)
    {
    	preallocation=prealloc;
    }
     
    /*! \brief Set if in copy or move mode
    \param setMove If true is in moving mode
    */
    void copyThread::setMovingMode(const bool setMove)
    {
    	DEBUGCONSOLE(30,"copyThread::setMovingMode","Set copy thread as moving mode");
    	movingMode=setMove;
    }
     
    /*! \brief Set the copy info and options before runing
    \param doRightCopy If true copy the right of the file
    */
    void copyThread::setRightCopy(const int doRightCopy)
    {
    	#if (DEBUG>0)
    	if(doRightCopy)
    		DEBUGCONSOLE(70,"copyThread::setRightCopy","doRightCopy: true");
    	else
    		DEBUGCONSOLE(70,"copyThread::setRightCopy","doRightCopy: false");
    	#endif
    	RightCopy=doRightCopy;
    }
     
    /*! \brief Set if need compare check sum
    \param doCheckSum If true check the checksum of the files after the copy
    */
    void copyThread::setCheckSum(int doCheckSum)
    {
    	#if (DEBUG>0)
    	if(doCheckSum)
    	{
    		DEBUGCONSOLE(50,"copyThread::setCheckSum","doCheckSum: true");
    	}
    	else
    	{
    		DEBUGCONSOLE(50,"copyThread::setCheckSum","doCheckSum: false");
    	}
    	#endif
    	CheckSum=doCheckSum;
    }
     
    /// \brief For give timer envery X ms
    void copyThread::timeOfTheBlockCopyFinished()
    {
    	tooLateForWait=true;
    	waitTimerIsEnd.wakeAll();
    }
     
    /*! \brief Add one entry to dir list
    \param theDir Is set for define the source folder, it need be requested in moving mode
    \see movingMode and AddFolderThread::putToDirList()
    */
    void copyThread::addEntryToDirList(const QString& theDir)
    {
    	if(movingMode)
    	{
    		DEBUGCONSOLE(90,"copyThread::addEntryToDirList","dir: \""+theDir+"\"");
    		sourceDirList<<theDir;
    	}
    	else
    	{
    		DEBUGCONSOLE(10,"copyThread::addEntryToDirList","copy mode, can't have an folder here");
    	}
    }
     
    /** \brief add one entry to empty dir destination list
    \param theDir Which empty destination folder should be created  */
    void copyThread::addEntryToEmptyDestinationDirList(const QString& theDir)
    {
    	emptyDestDir<<theDir;
    }
     
    /** \brief Remove all the source empty folder
    \return Return true if success */
    bool copyThread::removeAllFolderEmpty(const QString& TheDir)
    {
    	DEBUGCONSOLE(90,"copyThread::removeAllFolderEmpty","The dir: "+TheDir);
    	bool ok=true;
    	QDir dir(TheDir);
    	QFileInfoList list = dir.entryInfoList(QDir::AllEntries|QDir::NoDotAndDotDot|QDir::Hidden|QDir::System,QDir::DirsFirst);
    	if(list.isEmpty())
    	{
    		DEBUGCONSOLE(90,"copyThread::removeAllFolderEmpty","The folder is empty");
    	}
    	else
    	{
    		DEBUGCONSOLE(90,"copyThread::removeAllFolderEmpty","Listing");
    		for (int i = 0; i < list.size(); ++i)
    		{
    			QFileInfo fileInfo(list.at(i));
    			if(!fileInfo.isDir())
    			{
    				DEBUGCONSOLE(90,"copyThread::removeAllFolderEmpty","found a file: "+fileInfo.fileName());
    			}
    			else
    			{
    				//return the fonction for scan the new folder
    				ok=ok && removeAllFolderEmpty(TheDir+fileInfo.fileName()+'/');
    				ok=ok && dir.rmdir(TheDir+fileInfo.fileName()+'/');
    			}
    		}
    	}
    	return ok;
    }
     
    /// \brief Flush the last thread
    bool copyThread::flush(bool skipFirstOnError)
    {
    	DEBUGCONSOLE(90,"copyThread::flush","start");
    	bool stateOK=true;
    	tempSource="";
     
    	//create here the empty destination folder
    	while(!emptyDestDir.isEmpty())
    	{
    		DEBUGCONSOLE(90,"copyThread::flush","emptyDestDir.isEmpty() is not empty");
    		dest_dir_folder->setPath(emptyDestDir.at(0));
    		if(!dest_dir_folder->exists())
    		{
    			if(!dest_dir_folder->mkpath(emptyDestDir.at(0)))
    			{
    				DEBUGCONSOLE(10,"copyThread::flush","Unable to create the folder: "+emptyDestDir.at(0));
    				setErrorMessage(tr("Unable to create the folder: ")+emptyDestDir.at(0));
    				if(skipFirstOnError)
    					skipFirstOnError=false;
    				else
    				{
    					emit errorOnFlush(emptyDestDir.at(0));
    					return false;
    				}
    				stateOK=false;
    			}
    			else
    			{
    				DEBUGCONSOLE(90,"copyThread::flush","Folder created: "+emptyDestDir.at(0));
    			}
    		}
    		else
    		{
    			DEBUGCONSOLE(90,"copyThread::flush","dest_dir_folder->exists() not exists");
    		}
    		emptyDestDir.removeAt(0);
    	}
     
    	//remove here the empty source folder when is in moving mode
    	if(movingMode)
    	{
    		// remove recusively here the sourceDirList list
    		while(!sourceDirList.isEmpty())
    		{
    			DEBUGCONSOLE(90,"copyThread::flush","Clean this folder for removing: "+sourceDirList.at(0));
    			if(!removeAllFolderEmpty(sourceDirList.at(0)))
    				stateOK=false;
    			if(sourceDirList.at(0)!=getMountPoint(sourceDirList.at(0)))
    			{
    				QDir *thedir = new QDir();
    				if(!thedir->rmdir(sourceDirList.at(0)))
    				{
    					DEBUGCONSOLE(10,"copyThread::flush","Unable to remove the folder: "+sourceDirList.at(0));
    					setErrorMessage(tr("Unable to remove the folder: ")+sourceDirList.at(0));
    					if(skipFirstOnError)
    						skipFirstOnError=false;
    					else
    					{
    						emit errorOnFlush(sourceDirList.at(0));
    						return false;
    					}
    				}
    			}
    			else
    			{
    				DEBUGCONSOLE(10,"copyThread::flush","Folder is the mount point: "+sourceDirList.at(0));
    			}
    			sourceDirList.removeAt(0);
    		}
    	}
     
    	return stateOK;
    }
     
    /** \brief try open file in special mode
    \param theFile Pointer on the file
    \param theModeShouldBeUsed Wich mode should be used
    */
    bool copyThread::tryOpenFileInSpecialMode(QFile *theFile,QIODevice::OpenMode theModeShouldBeUsed)
    {
            DEBUGCONSOLE(90,"copyThread::tryOpenFileInSpecialMode","start");
    	//if file is already open
    	if(theFile->isOpen())
    	{
    		//check the open mode
    		if(theFile->openMode()!=theModeShouldBeUsed)
    		{
    			theFile->close();
    			return theFile->open(theModeShouldBeUsed);
    		}
    		else
    			return true;
    	}
    	else
    		return theFile->open(theModeShouldBeUsed);
    }
     
    /*! \brief Set the max speed
    \param tempMaxSpeed Set the max speed in KB/s, 0 for no limit */
    void copyThread::setMaxSpeed(const int tempMaxSpeed)
    {
    	if(tempMaxSpeed>=0)
    	{
    		maxSpeed=tempMaxSpeed;
    		DEBUGCONSOLE(50,"copyThread::setMaxSpeed",QString("tempMaxSpeed=")+QString::number(tempMaxSpeed));
    		if(maxSpeed>0)
    		{
    			int NewInterval,newMultForBigSpeed=0;
    			do
    			{
    				newMultForBigSpeed++;
    				NewInterval=(blockSizeCurrent*newMultForBigSpeed)/(maxSpeed);
    			}
    			while (NewInterval<MINTIMERINTERVAL);
    			MultForBigSpeed=newMultForBigSpeed;
    			if(clockForTheCopySpeed.isActive())
    			{
    				clockForTheCopySpeed.stop();
    				clockForTheCopySpeed.setInterval(NewInterval);
    				clockForTheCopySpeed.start();
    			}
    			else
    				clockForTheCopySpeed.setInterval(NewInterval);
    			DEBUGCONSOLE(90,"copyThread::setMaxSpeed","setInterval at: "+QString::number(NewInterval)+"ms for "+QString::number(MultForBigSpeed)+" block(s).");
    			DEBUGCONSOLE(90,"copyThread::setMaxSpeed","for speed of: "+QString::number(((blockSizeCurrent*MultForBigSpeed)/NewInterval))+"KB/s");
    			if(!clockForTheCopySpeed.isActive() && this->isRunning())
    				clockForTheCopySpeed.start();
    		}
    		else
    		{
    			if(clockForTheCopySpeed.isActive())
    				clockForTheCopySpeed.stop();
    			waitTimerIsEnd.wakeAll();
    		}
    	}
    }
     
    /*! \brief Query for stop the current thread
    \see stopIt, run() and stop()
    */
    void copyThread::stopTheCopy()
    {
    	DEBUGCONSOLE(50,"copyThread::stopTheCopy","stopTheCopy");
    	if(!stopIt)
    	{
    		stopIt=true;
    		if(clockForTheCopySpeed.isActive())
    		{
    			clockForTheCopySpeed.stop();
    		}
    		DEBUGCONSOLE(90,"copyThread::stopTheCopy","wakeAll");
    		waitTimerIsEnd.wakeAll();
    	}
    	if(currentStat==copyThread::Paused)
    		controlMutex.wakeAll();
    }
     
    /*! \brief Run the copy
    \warning The pointer sould be given and thread initilised
    \see QObjectOfMwindow(), stopTheCopy() and stop()
    */
    void copyThread::run()
    {
    // ...
    }
     
    /*! \brief Stop the copy thread
    \see stopIt, stopTheCopy() and run()
    */
    void copyThread::stop()
    {
    	stopTheCopy();
    	stopped = true;
    }
     
    /** \brief The destructor
    \see copyThread()
    */
    copyThread::~copyThread()
    {
    	stopTheCopy();
    	currentStat=copyThread::Paused;
    	delete sourceFile;
    	delete destinationFile;
    	delete dest_dir_folder;
    }

  4. #4
    Expert éminent
    Avatar de koala01
    Homme Profil pro
    aucun
    Inscrit en
    Octobre 2004
    Messages
    11 633
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 53
    Localisation : Belgique

    Informations professionnelles :
    Activité : aucun

    Informations forums :
    Inscription : Octobre 2004
    Messages : 11 633
    Par défaut
    Attention, les identifiants doivent rester uniques...

    C'est à dire que, au sein d'une même structure, tu ne peux pas définir d'un coté une énumération nommée currentStat et d'un autre déclarer un accesseur dont le nom serait... currentStat() (qui, soit dit en passant, devrait être déclaré comme constant et qui *pourrait* être inliné, comme tout bon accesseur renvoyant une information sans avoir à faire de manipulation)...

    Pour éviter ce genre de problème, j'ai pris l'habitude de préfixer l'identifiant de mes énumération avec un 'e' pour... énumeration (ce qui donnerait eCurrentStat pour l'énumération et laisserait currentStat disponible comme nom de fonction)...

    Je ne suis pas particulièrement partisant de la notation [EDIT]Au temps pour moi, il s'agit bien sur de la notation hongroise et non polonaise [/EDIT], mais, je dois avouer que, dans le cas des énumérations, cela s'avère parfois intéressant

    Evidemment, je ne fais que présenter mon habitude sur ce coup, en donnant la raison qui me pousse à agir ainsi, mais il n'y a aucune obligation de te ralier à mon point de vue
    A méditer: La solution la plus simple est toujours la moins compliquée
    Ce qui se conçoit bien s'énonce clairement, et les mots pour le dire vous viennent aisément. Nicolas Boileau
    Compiler Gcc sous windows avec MinGW
    Coder efficacement en C++ : dans les bacs le 17 février 2014
    mon tout nouveau blog

  5. #5
    Rédacteur
    Avatar de 3DArchi
    Profil pro
    Inscrit en
    Juin 2008
    Messages
    7 634
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2008
    Messages : 7 634
    Par défaut
    Disons qu'il y a des subtilités toujours surprenantes avec le C++.
    Voilà quelque chose qui compile :
    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
     
    class copyThread
    {
    public:
    	enum currentStat {
    	Stopped,
    	Paused,
    	Running
    	};
    	copyThread::currentStat theCurrentStat;
       currentStat currentStat(){return Stopped;}
    };
    int main()
    {
       copyThread c;
    //   copyThread::currentStat e(c.currentStat()); -> erreur
       enum copyThread::currentStat e(c.currentStat()); // -> OK
     
       return 5;
     
    }
    En revanche, je serais de l'avis de Koala : ne pas mélanger les noms pour désigner des choses aussi différentes.

  6. #6
    Expert éminent
    Avatar de koala01
    Homme Profil pro
    aucun
    Inscrit en
    Octobre 2004
    Messages
    11 633
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 53
    Localisation : Belgique

    Informations professionnelles :
    Activité : aucun

    Informations forums :
    Inscription : Octobre 2004
    Messages : 11 633
    Par défaut
    Citation Envoyé par 3DArchi Voir le message
    Disons qu'il y a des subtilités toujours surprenantes avec le C++.
    Voilà quelque chose qui compile :
    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
     
    class copyThread
    {
    public:
    	enum currentStat {
    	Stopped,
    	Paused,
    	Running
    	};
    	copyThread::currentStat theCurrentStat;
       currentStat currentStat(){return Stopped;}
    };
    int main()
    {
       copyThread c;
    //   copyThread::currentStat e(c.currentStat()); -> erreur
       enum copyThread::currentStat e(c.currentStat()); // -> OK
     
       return 5;
     
    }
    En revanche, je serais de l'avis de Koala : ne pas mélanger les noms pour désigner des choses aussi différentes.
    D'autant plus que l'utilisation des subtilités n'est pas vraiment de nature à faciliter la relecture...

    Je ne nie pas que, dans certains cas, il soit indispensable d'envisager de travailler à coup de "subtilités", mais, en dehors de ces cas particuliers, il vaut mieux essayer en permanence de garder le code "aussi simple que possible": nous aurons déjà largement assez d'occasions de le rendre plus complexe sans en rajouter "juste parce qu'on peut le faire"
    A méditer: La solution la plus simple est toujours la moins compliquée
    Ce qui se conçoit bien s'énonce clairement, et les mots pour le dire vous viennent aisément. Nicolas Boileau
    Compiler Gcc sous windows avec MinGW
    Coder efficacement en C++ : dans les bacs le 17 février 2014
    mon tout nouveau blog

  7. #7
    Membre éclairé
    Avatar de alpha_one_x86
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Décembre 2006
    Messages
    411
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Somme (Picardie)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Décembre 2006
    Messages : 411
    Par défaut
    Pour:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    if(currentStat!=Paused)
    Il me dit:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    CopyThread.cpp:65: error: expected primary-expression before '!=' token

  8. #8
    Rédacteur
    Avatar de 3DArchi
    Profil pro
    Inscrit en
    Juin 2008
    Messages
    7 634
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2008
    Messages : 7 634
    Par défaut
    1/As-tu modifié le nom de l'accesseur ou celui de l'enum pour ne plus avoir de confusion?
    2/Ta variable s'appelle theCurrentStat :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    if(theCurrentStat!=Paused)
    Ou
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    if(currentStat()!=Paused)

  9. #9
    Expert éminent
    Avatar de koala01
    Homme Profil pro
    aucun
    Inscrit en
    Octobre 2004
    Messages
    11 633
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 53
    Localisation : Belgique

    Informations professionnelles :
    Activité : aucun

    Informations forums :
    Inscription : Octobre 2004
    Messages : 11 633
    Par défaut
    petite précision
    Citation Envoyé par 3DArchi Voir le message
    2/Ta variable s'appelle theCurrentStat :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    if(theCurrentStat!=Paused)
    Ou
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    if(currentStat()!=Paused)
    uniquement dans les fonctions membre de copyThread...

    Autrement, c'est
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    if(nom_variable.currentStat()!=Paused)
    N'oublions pas que currentStat est un membre privé et que currentStat() n'est pas statique (il faut donc partir d'une instance de copyThread)
    A méditer: La solution la plus simple est toujours la moins compliquée
    Ce qui se conçoit bien s'énonce clairement, et les mots pour le dire vous viennent aisément. Nicolas Boileau
    Compiler Gcc sous windows avec MinGW
    Coder efficacement en C++ : dans les bacs le 17 février 2014
    mon tout nouveau blog

  10. #10
    Membre éclairé
    Avatar de alpha_one_x86
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Décembre 2006
    Messages
    411
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Somme (Picardie)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Décembre 2006
    Messages : 411
    Par défaut
    Dernier probléme de template que j'ai jamais eu (j'en ai déjà résolut 53):
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    if(!theCopyList.size())
    Qui marche bien avec un QList traditionnel, voila mon erreur:
    CopyThread.cpp:434: error: passing 'volatile QList<QList<QString> >' as 'this' argument of 'int QList<T>::size() const [with T = QList<QString>]' discards qualifiers

  11. #11
    Rédacteur
    Avatar de 3DArchi
    Profil pro
    Inscrit en
    Juin 2008
    Messages
    7 634
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2008
    Messages : 7 634
    Par défaut
    Salut,
    Ca ressemble à un problème de const. Peux-tu montrer l'ensemble de la fonction?

  12. #12
    Membre éclairé
    Avatar de alpha_one_x86
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Décembre 2006
    Messages
    411
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Somme (Picardie)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Décembre 2006
    Messages : 411
    Par défaut
    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
    /*! \brief Run the copy
    \warning The pointer sould be given and thread initilised
    \see QObjectOfMwindow(), stopTheCopy() and stop()
    */
    void copyThread::run()
    {
    	stopIt=false;
    	errorMessageInCopy="";
    	stopped=false;					///< Pointer on the destination file
    	QByteArray blockArray;				///< For store the block array///< Store the result of the opening
    	QDir destinationFolder;				///< Just for do operation on folder, static method is missing
    	QFileInfo *destFolderInfo=new QFileInfo();	///< Just for do operation on folder, static method is missing
    	bool resultOpen;
    	mutexWaitControl.lock();
    	theCurrentStat=copyThread::Running;
    	#if (DEBUG>0)
    	if(!theCopyList.size())
    		DEBUGCONSOLE(10,"copyThread::run","theCopyList.size()==0");
    	#endif
            while(theCopyList.size())
    	{
    		startCopyCopyList:
    		/**************************
                            extra check
                    **************************/
    		#if (DEBUG>0)
    		if(sourceFile->isOpen())
    			DEBUGCONSOLE(10,"copyThread::run","source: \""+sourceFile->fileName()+"\" is already open");
    		if(destinationFile->isOpen())
    			DEBUGCONSOLE(10,"copyThread::run","destination: \""+destinationFile->fileName()+"\" is already open");
    		if(theCopyList.first().at(0).isEmpty())
    		{
    			DEBUGCONSOLE(10,"copyThread::run","The source file path is empty");
    			return;
    		}
    		if(theCopyList.first().at(1).isEmpty())
    		{
    			DEBUGCONSOLE(10,"copyThread::run","The destination file path is empty");
    			return;
    		}
    .........

Discussions similaires

  1. Problème avec .configure dans une classe
    Par Instanton dans le forum Tkinter
    Réponses: 2
    Dernier message: 29/12/2007, 09h37
  2. [POO] Probléme de syntaxe dans une classe
    Par jewelz dans le forum Langage
    Réponses: 3
    Dernier message: 03/11/2007, 03h57
  3. Problème de setInterval dans une Classe
    Par jeremie74 dans le forum ActionScript 1 & ActionScript 2
    Réponses: 1
    Dernier message: 21/08/2007, 19h45
  4. Problème Access Violation dans une classe
    Par randriano dans le forum C++Builder
    Réponses: 1
    Dernier message: 11/04/2007, 18h49
  5. problème d'accès dans une classe dérivée!
    Par chrono23 dans le forum C++
    Réponses: 47
    Dernier message: 10/10/2006, 11h22

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