« Programmation Qt/Signaux et slots » : différence entre les versions
Contenu supprimé Contenu ajouté
→Exercice : la fenêtre se ferme après avoir cliquer sur un bouton : cliquer -> cliqué |
<source> bientôt obsolète, remplacé par <syntaxhighlight> |
||
Ligne 20 :
{{FichierDébut|Telechargement.h|largeur=70%|info=(extrait) Définition du signal|icon=Crystal128-source-h.svg}}
<
class Telechargement: public QObject
{
Ligne 32 :
// ...
}
</syntaxhighlight>
{{FichierFin}}
Ligne 39 :
{{FichierDébut|Telechargement.cpp|largeur=70%|info=(extrait) Utilisation du signal|icon=Crystal128-source-cpp.svg}}
<
void Telechargement::Terminer()
{
Ligne 47 :
emit fichierRecu( this->m_chemin_fichier );
}
</syntaxhighlight>
{{FichierFin}}
Ligne 57 :
{{FichierDébut|Stockage.h|largeur=70%|info=(extrait) Déclaration des slots|icon=Crystal128-source-h.svg}}
<
class Stockage: public QObject
{
Ligne 71 :
// ...
}
</syntaxhighlight>
{{FichierFin}}
{{FichierDébut|Stockage.cpp|largeur=70%|info=(extrait) Définition des slots|icon=Crystal128-source-cpp.svg}}
<
// ...
Ligne 94 :
// ...
</syntaxhighlight>
{{FichierFin}}
Ligne 117 :
{{FichierDébut|Main.cpp|info=(extrait) Connextion entre signaux et slots|icon=Crystal128-source-cpp.svg}}
<
// ...
Ligne 129 :
// ...
</syntaxhighlight>
{{FichierFin}}
Ligne 135 :
Par exemple, pour successivement copier puis supprimer le fichier et enfin afficher un message quand le téléchargement est terminé :
{{FichierDébut|Main.cpp|info=(extrait) Connextion entre signaux et slots|icon=Crystal128-source-cpp.svg}}
<
// ...
Ligne 152 :
// ...
</syntaxhighlight>
{{FichierFin}}
Ligne 169 :
<code>connect()</code> est une méthode statique. On écrit donc :
<
La méthode <code>connect</code> prend 4 arguments :
Ligne 179 :
===Exercice : la fenêtre se ferme après avoir cliqué sur un bouton===
Lançons-nous dans la création du code de <code>mafenetre.cpp</code>.
< //main.cpp
#include <QApplication>
Ligne 194 ⟶ 196 :
return app.exec();
}
</syntaxhighlight>
<
//MaFenetre.h
#ifndef DEF_MAFENETRE
Ligne 215 ⟶ 217 :
#endif
</syntaxhighlight>
<
//MaFenetre.cpp
#include "MaFenetre.h"
Ligne 232 ⟶ 234 :
QObject::connect(m_bouton, SIGNAL(clicked()), qApp, SLOT(quit()));
}
</syntaxhighlight>
Exécutons la commande <code>qmake</code>, puis testons notre code. Une fenêtre s'ouvre.
Ligne 246 ⟶ 248 :
Voici le code:
<
//MaFenetre.h
#ifndef DEF_MAFENETRE
Ligne 267 ⟶ 269 :
#endif
</syntaxhighlight>
<
#include "MaFenetre.h"
Ligne 286 ⟶ 288 :
QObject::connect(m_aPropos, SIGNAL(clicked()), qApp, SLOT(aboutQt()));
}
</syntaxhighlight>
On compile maintenant, et le bouton "Quitter" ferme toujours l'application. Quant à "À propos", il provoque l'ouverture de la fenêtre "À propos de Qt".
|