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 :

Inclusion croisé, haut niveau


Sujet :

Threads & Processus C++

  1. #1
    Membre régulier
    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
    Points : 113
    Points
    113
    Par défaut Inclusion croisé, haut niveau
    Bonjour, voila mes 2 .h qui pose problèmes, ce probléme n'est pas spécifique à Qt:
    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
    #ifndef WRITETHREAD_H
    #define WRITETHREAD_H
     
    #include <QThread>
    #include <QByteArray>
    #include <QFile>
    #include <QObject>
    #include <QList>
    #include <QMutex>
    #include <QWaitCondition>
     
    #include "CopyThread.h"
     
    //the structures
    typedef struct {
    	quint64 id;
    	QString source;
    	qint64 size;
    	QString destination;
    } copyItemInternal;
     
    typedef struct {
    	QList<int> idsRemove;
    	QList<int> idsAction;
    } returnIdsTransaction;
     
    class WriteThread : public QThread
    {
    	Q_OBJECT
    	public:
    		WriteThread(copyThread *parent);
    		void setFiles(QFile * source,QFile * destination,copyItemInternal theItem);
    		void stop();
    		void pause();
    		void resume();
    		void addNewBlock(QByteArray newBlock);
    		enum currentStat {
    		Stopped,
    		Paused,
    		PausedInError,
    		Running
    		};
    		/// \brief set action on error
    		void errorAction(int action);
    		/// \brief return the statut
    		currentStat getCurrentStat();
    		void setMovingMode(bool movingMode);
    	signals:
    		/// \brief error on file or folder, bouton enable, file path, error message
    		void errorOnFile(int,QString,QString);
    	protected:
    		void run();
    	private:
    		volatile bool stopIt;		///< For store the stop query
    		volatile bool movingMode;	///< Set if is in moving mode
    		volatile int actionAfterUnlock;	///< For action after unlock the mutex
    		QWaitCondition controlMutex;	///< For stop/pause/resume copy
    		QMutex mutexWaitControl;	///< For use the mutex to control the copy
    		currentStat theCurrentStat;	///< The current stat
    		QFile *source;			///< For have global copie progression
    		QFile *destination;		///< For have global copie progression
    		QList<QByteArray> theBlockList;	///< Store the block list
    		copyItemInternal theItem;	///< Store current item for put at end if needed
    		copyThread *parent;		///< Store the parent object
    };
     
    #endif // WRITETHREAD_H
    Et:
    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
    /***************************************************************************
                                      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>
    #include <QMutexLocker>
     
    #include "WriteThread.h"
     
    /** \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(quint64 id,const QString& source,qint64 size,const QString& destination);
    	//pause the copy
    	void pauseCopy();
    	//resume the copy
    	void resumeCopy();
    	//stop the current copy
    	void stopTheCopy();
    	//skip the current file
    	void skipCurrentFile();
     
    	//return the progression percent
    	int getProgressionPercent(const int max=100);
    	//return the progression percent
    	int getProgressionPercentTotal(const int max=100);
    	//get copy speed in byte per second
    	QString getCopySpeed();
    	//set thread write
    	void setThreadWrite(int useWriteThread);
    	//insert at end without count
    	void insterAtEndWithoutCount(copyItemInternal theItem);
    public:
    	enum currentStat {
    			Stopped,
    			Paused,
    			Running
    	}; ///< Enumeration for have copy state
    	//the contructor
    	copyThread();
    	//the desytructor
    	~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
    	QString getCurrentFileCopied();
    	/// \brief return text overall
    	QString getTextOverall();
    	/// \brief lenght of copy list
    	int lenghtOfCopyList();
    	/// \brief number of item removed
    	int getNumberOfItemRemoved();
    	/// \brief return the statut
    	currentStat getCurrentStat();
    	/// \brief Return string for the
    	static QString intToQtringSize(qint64 num);
    	//remove one entry
    	void removeItems(QList<int> ids);
    	//put on top
    	returnIdsTransaction putOnTop(QList<int> ids);
    	//move up
    	returnIdsTransaction moveUp(QList<int> ids);
    	//move down
    	returnIdsTransaction moveDown(QList<int> ids);
    	//put on bottom
    	returnIdsTransaction putOnBottom(QList<int> ids);
    signals:
    	/// \brief error on file or folder, 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
    	void removeAllFolderEmpty(const QString& TheDir);
    	//try open file in special mode
            bool tryOpenFileInSpecialMode(QFile *theFile,QIODevice::OpenMode theModeShouldBeUsed);
    	//remove source folder and create destination folder
    	void 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
    	qint64 firstScanTot;		///< Store total size at first scan
    	qint64 firstScanCur;		///< Store curent size at first scan
    	volatile int maxSpeed;		///< The max speed in MB/s, 0 for no limit
    	volatile bool RightCopy;	///< Do rights copy
    	volatile bool movingMode;	///< Set if is in moving mode
    	volatile bool tooLateForWait;	///< Flag for know if it's too late for wait the next timer time out
    	volatile bool preallocation;	///< Flag for know if need preallocation
    	volatile bool keepDate;		///< For keep date file
    	volatile bool useWriteThread;	///< For set fi need write thread
    	QTime intervalCopySpeed;	///< For detect the interval beteew 2 copy speed mesurement
    	volatile 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
    	volatile int MultForBigSpeed;	///< Multiple for count the number of block needed
    	volatile int numberOfBlockCopied;///< Multiple for count the number of block copied
    	volatile 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
    	QMutex MultiThreadCopyList;	///< For be thread safe while operate on copy list
    	QMutex ErrorWaitAction;		///< For prevent multithread bug when error
    	int numberOfItemRemoved;	///< For unmber of item removed
    	int NumberOfFileTot;		///< For number of file to copy
    	int NumberOfFileCopied;		///< For number of file to copied
    	QString syntetizedStringCurrentFile;///< For store sytetized string for current file
    	QString syntetizedStringOverall;///< For store sytetized string for overall
    	bool copyHadBegin;		///< Store if copy had begin
    	bool skipThecurrentFile;	///< Skip the current file
    	// for copy list
    	QList<copyItemInternal> theCopyList;
    private slots:
    	void timeOfTheBlockCopyFinished();
    	void pre_operation();
    	void post_operation();
    };
     
    #endif
    Et il s'inclut matuellement car pour chaque objet copyThread il as des objets WriteThread, et chaque objet WriteThread stock un pointeur sur son objet copyThread parent.
    Donc la question est: Comment faire pour que ça marche.
    Merci d'avance.
    Développeur d'Ultracopier

  2. #2
    Membre éprouvé
    Avatar de méphistopheles
    Profil pro
    Inscrit en
    Janvier 2005
    Messages
    1 551
    Détails du profil
    Informations personnelles :
    Âge : 36
    Localisation : France

    Informations forums :
    Inscription : Janvier 2005
    Messages : 1 551
    Points : 1 220
    Points
    1 220
    Par défaut
    c'est un problème courant, mais il y as une solution relativement simple: ajoute avant la déclaration de writethread:normalement (si je me trompe pas, ça devrais suffire. (tant que tu n'utilise que des pointeurs sur copyThread (et pas des copyThread eux mêmes))).

    Bonne chance
    Méphistophélès
    Si la solution ne résout pas votre problème, changez le problème...
    Cours et tutoriels C++ - FAQ C++ - Forum C++.

  3. #3
    Membre régulier
    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
    Points : 113
    Points
    113
    Par défaut
    D'origine j'ai l'erreur:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    class WriteThread : public QThread
    {
    	Q_OBJECT
    	public:
    		WriteThread(copyThread * parent);
    J'ai toujours l'erreur:
    WriteThread.h:44: error: expected `)' before '*' token
    WriteThread.h:77: error: ISO C++ forbids declaration of 'copyThread' with no type
    WriteThread.h:77: error: expected ';' before '*' token
    Et quand je met:
    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
    /***************************************************************************
                                      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>
    #include <QMutexLocker>
     
    /** \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 WriteThread;
     
    class copyThread : public QThread
    {
    	Q_OBJECT
    public slots:
    Il ne trouve plus aucun type.

    Et dans le sens que tu as dit ça me génére aussi plein d'erreur:
    FEwindow.h:54: error: declaration of 'QAction* CopyFileExistsWindow::overwriteIfNotSame'
    FEwindow.h:47: error: conflicts with previous declaration 'void CopyFileExistsWindow::overwriteIfNotSame()'
    FEwindow.h:55: error: declaration of 'QAction* CopyFileExistsWindow::overwriteIfNewer'
    FEwindow.h:49: error: conflicts with previous declaration 'void CopyFileExistsWindow::overwriteIfNewer()'
    FEwindow.cpp: In constructor 'CopyFileExistsWindow::CopyFileExistsWindow(QWidget*)':
    FEwindow.cpp:36: error: invalid use of member (did you forget the '&' ?)
    FEwindow.cpp:37: error: no matching function for call to 'QMenu::addAction(<unresolved overloaded function type>)'
    /usr/include/qt4/QtGui/qmenu.h:89: note: candidates are: QAction* QMenu::addAction(const QString&)
    /usr/include/qt4/QtGui/qmenu.h:90: note: QAction* QMenu::addAction(const QIcon&, const QString&)
    /usr/include/qt4/QtGui/qmenu.h:91: note: QAction* QMenu::addAction(const QString&, const QObject*, const char*, const QKeySequence&)
    /usr/include/qt4/QtGui/qmenu.h:92: note: QAction* QMenu::addAction(const QIcon&, const QString&, const QObject*, const char*, const QKeySequence&)
    /usr/include/qt4/QtGui/qwidget.h:549: note: void QWidget::addAction(QAction*)
    FEwindow.cpp:38: error: invalid use of member (did you forget the '&' ?)
    FEwindow.cpp:39: error: no matching function for call to 'QMenu::addAction(<unresolved overloaded function type>)'
    /usr/include/qt4/QtGui/qmenu.h:89: note: candidates are: QAction* QMenu::addAction(const QString&)
    /usr/include/qt4/QtGui/qmenu.h:90: note: QAction* QMenu::addAction(const QIcon&, const QString&)
    /usr/include/qt4/QtGui/qmenu.h:91: note: QAction* QMenu::addAction(const QString&, const QObject*, const char*, const QKeySequence&)
    /usr/include/qt4/QtGui/qmenu.h:92: note: QAction* QMenu::addAction(const QIcon&, const QString&, const QObject*, const char*, const QKeySequence&)
    /usr/include/qt4/QtGui/qwidget.h:549: note: void QWidget::addAction(QAction*)
    FEwindow.cpp:63: error: no matching function for call to 'CopyFileExistsWindow::connect(<unresolved overloaded function type>, const char [13], CopyFileExistsWindow* const, const char [22])'
    /usr/include/qt4/QtCore/qobject.h:202: note: candidates are: static bool QObject::connect(const QObject*, const char*, const QObject*, const char*, Qt::ConnectionType)
    /usr/include/qt4/QtCore/qobject.h:307: note: bool QObject::connect(const QObject*, const char*, const char*, Qt::ConnectionType) const
    FEwindow.cpp:65: error: no matching function for call to 'CopyFileExistsWindow::connect(<unresolved overloaded function type>, const char [13], CopyFileExistsWindow* const, const char [20])'
    /usr/include/qt4/QtCore/qobject.h:202: note: candidates are: static bool QObject::connect(const QObject*, const char*, const QObject*, const char*, Qt::ConnectionType)
    /usr/include/qt4/QtCore/qobject.h:307: note: bool QObject::connect(const QObject*, const char*, const char*, Qt::ConnectionType) const
    FEwindow.cpp: In member function 'void CopyFileExistsWindow::overwriteIfNotSame()':
    FEwindow.cpp:174: error: 'OVERWRITE_IFNOTSAME' was not declared in this scope
    FEwindow.cpp: In member function 'void CopyFileExistsWindow::overwriteAllwaysIfNotSame()':
    FEwindow.cpp:181: error: 'OVERWRITE_ALL_IFNOTSAME' was not declared in this scope
    FEwindow.cpp: In member function 'void CopyFileExistsWindow::overwriteIfNewer()':
    FEwindow.cpp:188: error: 'OVERWRITE_IFNEWER' was not declared in this scope
    FEwindow.cpp: In member function 'void CopyFileExistsWindow::overwriteAllwaysIfNewer()':
    FEwindow.cpp:195: error: 'OVERWRITE_ALL_IFNEWER' was not declared in this scope
    Et dans les 2 classes je travail avec des pointeurs sur l'autre classe.
    Développeur d'Ultracopier

  4. #4
    Membre éprouvé
    Avatar de méphistopheles
    Profil pro
    Inscrit en
    Janvier 2005
    Messages
    1 551
    Détails du profil
    Informations personnelles :
    Âge : 36
    Localisation : France

    Informations forums :
    Inscription : Janvier 2005
    Messages : 1 551
    Points : 1 220
    Points
    1 220
    Par défaut
    si tu regarde les erreurs que tu reçoit avec ma solution, tu t'aperçoit que :
    • ce ne sont pas les mêmes
    • elle ne sont pas lié à ton inclusions multiples

    Par conséquent, je pense que ma solution a bien réglé le problème abordé dans le début du sujet. néanmoins, si tu veux en être sûr, commente les lignes qui causent une erreur jusqu'à ce que ça compile.

    Ensuite, retire le "class copyThread;" et tu devrais voir des erreurs réapparaitre.

    bonne chance
    Méphistophélès
    Si la solution ne résout pas votre problème, changez le problème...
    Cours et tutoriels C++ - FAQ C++ - Forum C++.

  5. #5
    Membre régulier
    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
    Points : 113
    Points
    113
    Par défaut
    Apparemment c'est résolut après correction des erreurs. Merci à tous.
    Développeur d'Ultracopier

  6. #6
    Membre éprouvé
    Avatar de méphistopheles
    Profil pro
    Inscrit en
    Janvier 2005
    Messages
    1 551
    Détails du profil
    Informations personnelles :
    Âge : 36
    Localisation : France

    Informations forums :
    Inscription : Janvier 2005
    Messages : 1 551
    Points : 1 220
    Points
    1 220
    Par défaut
    Citation Envoyé par alpha_one_x86 Voir le message
    Apparemment c'est résolut après correction des erreurs. Merci à tous.
    Heureux de t'avoir aidé mais n'oublie pas le tag .
    ça fera plaisir aux modérateurs
    Méphistophélès
    Si la solution ne résout pas votre problème, changez le problème...
    Cours et tutoriels C++ - FAQ C++ - Forum C++.

  7. #7
    Futur Membre du Club
    Inscrit en
    Juin 2007
    Messages
    15
    Détails du profil
    Informations personnelles :
    Âge : 38

    Informations forums :
    Inscription : Juin 2007
    Messages : 15
    Points : 9
    Points
    9
    Par défaut
    Bonjour à vous,

    Je me permet de revenir sur ce sujet, parce que j'ai le meme probleme et je ne comprends pas ce que dis Mephistopheles:
    c'est un problème courant, mais il y as une solution relativement simple: ajoute avant la déclaration de writethread:
    Il faut mettre ça où exactement?

    Merci d'avance

  8. #8
    Futur Membre du Club
    Inscrit en
    Juin 2007
    Messages
    15
    Détails du profil
    Informations personnelles :
    Âge : 38

    Informations forums :
    Inscription : Juin 2007
    Messages : 15
    Points : 9
    Points
    9
    Par défaut
    Oups désolé pour le double post, mais ma réponse était dans la FAQ
    http://cpp.developpez.com/faq/cpp/?p...erence_croisee

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

Discussions similaires

  1. Liste des langages de haut niveau ?
    Par spirit_epock dans le forum Langages de programmation
    Réponses: 14
    Dernier message: 15/03/2006, 13h25
  2. Réponses: 4
    Dernier message: 07/12/2005, 00h05
  3. C : langage de haut niveau ?
    Par Mandalar dans le forum C
    Réponses: 7
    Dernier message: 03/10/2005, 11h50
  4. PROBLEME haut niveau BACKUP
    Par Dev_Michael dans le forum Administration
    Réponses: 7
    Dernier message: 10/03/2005, 15h32

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