<?xml version="1.0" encoding="utf-8"?><?xml-stylesheet title="XSL formatting" type="text/xsl" href="http://doc.qtfr.org/feed/rss2/xslt" ?><rss version="2.0"
  xmlns:dc="http://purl.org/dc/elements/1.1/"
  xmlns:wfw="http://wellformedweb.org/CommentAPI/"
  xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
  <title>Documentation Qtfr - version_Qt4</title>
  <link>http://doc.qtfr.org/</link>
  <description>La documentation francophone sur Qt</description>
  <language>fr</language>
  <pubDate>Thu, 03 Sep 2009 16:42:30 +0200</pubDate>
  <copyright></copyright>
  <docs>http://blogs.law.harvard.edu/tech/rss</docs>
  <generator>Dotclear</generator>
  
    
  <item>
    <title>Interaction entre boost.signals et les signaux/slots Qt</title>
    <link>http://doc.qtfr.org/post/2008/05/21/Interaction-entre-boostsignals-et-les-signaux/slots-Qt</link>
    <guid isPermaLink="false">urn:md5:36453448a7fa62278b910f115736ec3e</guid>
    <pubDate>Wed, 21 May 2008 20:46:00 +0200</pubDate>
    <dc:creator>IrmatDen</dc:creator>
        <category>Tutoriels</category>
        <category>Boost</category><category>signaux-slots</category><category>version_Qt4</category>    
    <description>&lt;ul&gt;
&lt;li&gt;Comment faire cohabiter les signaux/slots de Qt avec la librairie boost.signals&amp;nbsp;?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Ce tutoriel est destiné à vous guider pour mettre en place une interaction entre boost.signals et le mécanisme de signaux/slots Qt.&lt;/p&gt;


&lt;p&gt;&lt;strong&gt;Version&lt;/strong&gt;&amp;nbsp;: Qt4 &lt;br /&gt;
&lt;strong&gt;Auteur&lt;/strong&gt;&amp;nbsp;: Denys Bulant (&lt;a href=&quot;http://forum.qtfr.org/profile.php?id=291&quot;&gt;IrmatDen&lt;/a&gt;)&lt;br /&gt;
&lt;strong&gt;Fil de discussion&lt;/strong&gt;&amp;nbsp;: &lt;a href=&quot;http://forum.qtfr.org/viewtopic.php?pid=41721&quot;&gt;Forum&lt;/a&gt;&lt;/p&gt;    &lt;h3&gt;Pré requis:&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;La connaissance du &lt;a href=&quot;http://doc.trolltech.com/4.4/signalsandslots.html&quot;&gt;fonctionnement des signaux/slots&lt;/a&gt; avec Qt&lt;/li&gt;
&lt;li&gt;Une connaissance basique de &lt;a href=&quot;http://www.boost.org/doc/libs/1_35_0/doc/html/signals.html&quot;&gt;boost.signals&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Une connaissance basique de &lt;a href=&quot;http://www.boost.org/doc/libs/1_35_0/libs/functional/index.html&quot;&gt;boost.functional&lt;/a&gt; (tout particulièrement les fonctions de binding)&lt;/li&gt;
&lt;/ul&gt;


&lt;h3&gt;Introduction&lt;/h3&gt;


&lt;p&gt;Il est intéressant de savoir faire ceci dans la mesure où vous désireriez utiliser des classes écrites en C++ pur avec les mécanismes Qt. Par exemple, une couche métier utilisant le mécanisme de boost.signals comme implémentation du pattern observateur, que vous désirez connecter à la couche IHM écrite à l'aide de Qt.&lt;br /&gt;
Toutefois, cet article n'est ni une introduction à Qt, ni à boost.signals.&lt;/p&gt;


&lt;h3&gt;Précautions et conflits&lt;/h3&gt;


&lt;p&gt;Premièrement, il y a un conflit entre boost et Qt au niveau du terme &quot;signals&quot;. En effet, Qt déclare celui-ci comme #define signals protected, tandis qu'il s'agit d'un type boost. Il y a plusieurs façons de résoudre ce conflit:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Inclure les en-têtes boost en premier&lt;/li&gt;
&lt;li&gt;Placer boost.signals dans son propre namespace (pour plus d'infos se référer à &lt;a href=&quot;http://www.boost.org/doc/libs/1_34_1/doc/html/signals/s04.html#id1633734&quot;&gt;la Q/R 3 de la FAQ boost.signals&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;Depuis Qt 4.1, Trolltech à ajouté le paramètre no_keywords à la liste des valeurs potentielles pour CONFIG. Ajouter CONFIG += no_keywords dans votre fichier pro vous permettra donc d'utiliser sans soucis boost.signal. Le bémol de cette solution est que les &quot;mots clés&quot; suivant disparaissent au profit des macros suivantes:&lt;/li&gt;
&lt;/ol&gt;
&lt;ul&gt;
&lt;li&gt;signals -&amp;gt; Q_SIGNALS&lt;/li&gt;
&lt;li&gt;slots -&amp;gt; Q_SLOTS&lt;/li&gt;
&lt;li&gt;emit -&amp;gt; Q_EMIT&lt;/li&gt;
&lt;li&gt;foreach -&amp;gt; Q_FOREACH&lt;/li&gt;
&lt;li&gt;forever -&amp;gt; Q_FOREVER&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Les slots de Qt sont des méthodes standard, qui ont en plus la possibilité de connaître son émetteur (à la condition sine qua non que son appel soit lié à l'émission d'un signal). L'usage de cette fonction est grandement déconseillé en temps normal (&lt;a href=&quot;http://doc.trolltech.com/4.4/qsignalmapper.html&quot;&gt;QSignalMapper&lt;/a&gt; devrait amplement suffir pour s'en passer). Mais dans certains rares cas, vous pouvez avoir absolument besoin de cette info&amp;nbsp;: dans ce cas pensez bien à vérifier que le &lt;code&gt;QObject*&lt;/code&gt; retourné n'est pas null. Dans ce dernier cas, c'est que le slot a été invoqué de façon normale (c'est ce que l'on fait en connectant un slot Qt à un signal boost).&lt;/p&gt;



&lt;h3&gt;Interaction boost.signals et signaux/slots Qt&lt;/h3&gt;


&lt;p&gt;Je vais maintenant aborder 3 interactions possibles entre ces 2 bibliothèques:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Utilisation d'un boost.signal connecté à un slot Qt&lt;/li&gt;
&lt;li&gt;Utilisation d'un boost.signal connecté à un signal Qt&lt;/li&gt;
&lt;li&gt;Utilisation d'un signal Qt connecté à une (ou des) fonction(s) C++ standard par le biais de boost.signals&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Vous trouverez un code d'exemple reprenant ces 3 aspect en pièce jointe de ce document. Dans ce code, n'oubliez pas de régler les valeurs de &lt;code&gt;LIBS&lt;/code&gt; et &lt;code&gt;INCLUDEPATH&lt;/code&gt; de manière à correspondre à votre configuration.&lt;/p&gt;


&lt;h4&gt;Utilisation d'un boost.signal connecté à un slot Qt&lt;/h4&gt;


&lt;p&gt;Un slot au sens Qt est en réalité une fonction standard. Par conséquent, il est trivial d'en connecter un à un signal boost.&lt;br /&gt;
La seule chose différente entre un slot et une méthode de classe standard est la possibilité de récupérer des infos sur l'objet appelant (par le biais de &lt;a href=&quot;http://doc.trolltech.com/4.3/qobject.html#sender&quot;&gt;QObject::sender()&lt;/a&gt;). Je tiens à souligner à nouveau le &quot;danger&quot; posé par cette méthode: si le slot n'est pas appelé par un signal, le &lt;code&gt;QObject*&lt;/code&gt; renvoyé sera null. Par conséquent, réduisez au minimum son utilisation, et vérifiez toujours la validité de l'objet renvoyé!&lt;/p&gt;

&lt;pre class=&quot;cpp&quot;&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;class&lt;/span&gt; QtClass : &lt;span style=&quot;color: #0000ff;&quot;&gt;public&lt;/span&gt; QObject
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
Q_OBJECT
&lt;span style=&quot;color: #0000ff;&quot;&gt;public&lt;/span&gt; slots:
    &lt;span style=&quot;color: #0000ff;&quot;&gt;void&lt;/span&gt; qtSlot&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;float&lt;/span&gt; x&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
        QObject *s = sender&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
        &lt;span style=&quot;color: #0000ff;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;s == &lt;span style=&quot;color: #0000dd;&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
            std::&lt;span style=&quot;color: #0000dd;&quot;&gt;cout&lt;/span&gt; &amp;lt;&amp;lt; &lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot;From internal connection:&amp;quot;&lt;/span&gt; &amp;lt;&amp;lt; std::&lt;span style=&quot;color: #00eeff;&quot;&gt;endl&lt;/span&gt;;
        &lt;span style=&quot;color: #0000ff;&quot;&gt;else&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;!s&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
            std::&lt;span style=&quot;color: #0000dd;&quot;&gt;cout&lt;/span&gt; &amp;lt;&amp;lt; &lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot;Unknown sender:&amp;quot;&lt;/span&gt; &amp;lt;&amp;lt; std::&lt;span style=&quot;color: #00eeff;&quot;&gt;endl&lt;/span&gt;;
        std::&lt;span style=&quot;color: #0000dd;&quot;&gt;cout&lt;/span&gt; &amp;lt;&amp;lt; &lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot;In QtClass::qtSlot(), x=&amp;quot;&lt;/span&gt; &amp;lt;&amp;lt; x &amp;lt;&amp;lt; std::&lt;span style=&quot;color: #00eeff;&quot;&gt;endl&lt;/span&gt;;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;;
&amp;nbsp;
&lt;span style=&quot;color: #0000ff;&quot;&gt;class&lt;/span&gt; NonQtClass
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
&lt;span style=&quot;color: #0000ff;&quot;&gt;public&lt;/span&gt;:
    &lt;span style=&quot;color: #0000ff;&quot;&gt;void&lt;/span&gt; boostSignalToQtSlot&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;QtClass *qc&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
        boost::&lt;span style=&quot;color: #00eeff;&quot;&gt;signal&lt;/span&gt;&amp;lt;void &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;float&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&amp;gt; sig;
        sig.&lt;span style=&quot;color: #00eeff;&quot;&gt;connect&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;boost::&lt;span style=&quot;color: #00eeff;&quot;&gt;bind&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&amp;amp;QtClass::&lt;span style=&quot;color: #00eeff;&quot;&gt;qtSlot&lt;/span&gt;, qc, _1&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
        sig&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000dd;&quot;&gt;3&lt;/span&gt;.14f&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;; 
&amp;nbsp;
&lt;span style=&quot;color: #0000ff;&quot;&gt;int&lt;/span&gt; main&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;int&lt;/span&gt; argc, &lt;span style=&quot;color: #0000ff;&quot;&gt;char&lt;/span&gt; **argv&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
    NonQtClass nqc;
    QtClass    qc;
&amp;nbsp;
    &lt;span style=&quot;color: #ff0000;&quot;&gt;// Déclenche un boost::signal attaché à un slot Qt:&lt;/span&gt;
    nqc.&lt;span style=&quot;color: #00eeff;&quot;&gt;boostSignalToQtSlot&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&amp;amp;qc&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
&amp;nbsp;
    &lt;span style=&quot;color: #0000ff;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #0000dd;&quot;&gt;0&lt;/span&gt;;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Sortie obtenue:&lt;/p&gt;
&lt;pre&gt;
Unknown sender:
In QtClass::qtSlot(), x=3.14
&lt;/pre&gt;



&lt;h4&gt;Utilisation d'un boost.signal connecté à un signal Qt&lt;/h4&gt;


&lt;p&gt;Un signal au sens Qt n'est qu'une méthode standard, le mot clé &lt;code&gt;signals&lt;/code&gt; étant redéfini par Qt comme &lt;code&gt;protected&lt;/code&gt;. Il est donc nécessaire de fournir une méthode permettant de déclencher ce signal avec le(s) paramètre(s) voulu(s). Il y a 2 approches possible; la première consiste à ajouter une méthode à votre classe Qt, la seconde à utiliser une classe de pont.&lt;br /&gt;
Bien que plus verbeuse, la seconde méthode permet de découpler réellement la couche utilisant Qt de la couche sans Qt en &quot;intercalant&quot; une couche servant d'aptateur. Ici, ce sera la première méthode qui sera illustrée; la seconde le sera dans le 3ème et dernier point.&lt;/p&gt;

&lt;pre class=&quot;cpp&quot;&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;class&lt;/span&gt; QtClass : &lt;span style=&quot;color: #0000ff;&quot;&gt;public&lt;/span&gt; QObject
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
Q_OBJECT
&amp;nbsp;
&lt;span style=&quot;color: #0000ff;&quot;&gt;public&lt;/span&gt;:
    QtClass&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
        connect&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000dd;&quot;&gt;this&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;SIGNAL&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;qtSignal&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;float&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;, &lt;span style=&quot;color: #0000dd;&quot;&gt;this&lt;/span&gt;, SLOT&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;qtSlot&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;float&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
    &lt;span style=&quot;color: #ff0000;&quot;&gt;// OBLIGATOIRE si on veut connecter un signal boost à un signal Qt: les signaux sont **protégés**&lt;/span&gt;
    &lt;span style=&quot;color: #0000ff;&quot;&gt;void&lt;/span&gt; triggerQtSignalEmission&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;float&lt;/span&gt; x&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
        emit qtSignal&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;x&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
&lt;span style=&quot;color: #0000ff;&quot;&gt;public&lt;/span&gt; slots:
    &lt;span style=&quot;color: #0000ff;&quot;&gt;void&lt;/span&gt; qtSlot&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;float&lt;/span&gt; x&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
        QObject *s = sender&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
        &lt;span style=&quot;color: #0000ff;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;s == &lt;span style=&quot;color: #0000dd;&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
            std::&lt;span style=&quot;color: #0000dd;&quot;&gt;cout&lt;/span&gt; &amp;lt;&amp;lt; &lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot;From internal connection:&amp;quot;&lt;/span&gt; &amp;lt;&amp;lt; std::&lt;span style=&quot;color: #00eeff;&quot;&gt;endl&lt;/span&gt;;
        &lt;span style=&quot;color: #0000ff;&quot;&gt;else&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;!s&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
            std::&lt;span style=&quot;color: #0000dd;&quot;&gt;cout&lt;/span&gt; &amp;lt;&amp;lt; &lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot;Unknown sender:&amp;quot;&lt;/span&gt; &amp;lt;&amp;lt; std::&lt;span style=&quot;color: #00eeff;&quot;&gt;endl&lt;/span&gt;;
        std::&lt;span style=&quot;color: #0000dd;&quot;&gt;cout&lt;/span&gt; &amp;lt;&amp;lt; &lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot;In QtClass::qtSlot(), x=&amp;quot;&lt;/span&gt; &amp;lt;&amp;lt; x &amp;lt;&amp;lt; std::&lt;span style=&quot;color: #00eeff;&quot;&gt;endl&lt;/span&gt;;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
signals:
    &lt;span style=&quot;color: #0000ff;&quot;&gt;void&lt;/span&gt; qtSignal&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;float&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;;
&amp;nbsp;
&lt;span style=&quot;color: #0000ff;&quot;&gt;class&lt;/span&gt; NonQtClass
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
&lt;span style=&quot;color: #0000ff;&quot;&gt;public&lt;/span&gt;:
    &lt;span style=&quot;color: #0000ff;&quot;&gt;void&lt;/span&gt; boostSignalToQtSignal&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;QtClass *qc&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
        boost::&lt;span style=&quot;color: #00eeff;&quot;&gt;signal&lt;/span&gt;&amp;lt;void &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;float&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&amp;gt; sig;
        sig.&lt;span style=&quot;color: #00eeff;&quot;&gt;connect&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;boost::&lt;span style=&quot;color: #00eeff;&quot;&gt;bind&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&amp;amp;QtClass::&lt;span style=&quot;color: #00eeff;&quot;&gt;triggerQtSignalEmission&lt;/span&gt;, qc, _1&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
        sig&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000dd;&quot;&gt;42&lt;/span&gt;.0f&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;;
&amp;nbsp;
&lt;span style=&quot;color: #0000ff;&quot;&gt;int&lt;/span&gt; main&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;int&lt;/span&gt; argc, &lt;span style=&quot;color: #0000ff;&quot;&gt;char&lt;/span&gt; **argv&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
    NonQtClass nqc;
    QtClass    qc;
&amp;nbsp;
    &lt;span style=&quot;color: #ff0000; font-style: italic;&quot;&gt;/* Déclenche un boost::signal lié à l'émission d'un signal Qt
       (on triche par l'utilisation d'une méthode intermédiaire obligatoire) */&lt;/span&gt;
    nqc.&lt;span style=&quot;color: #00eeff;&quot;&gt;boostSignalToQtSignal&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&amp;amp;qc&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
&amp;nbsp;
    &lt;span style=&quot;color: #0000ff;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #0000dd;&quot;&gt;0&lt;/span&gt;;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Sortie obtenue:&lt;/p&gt;
&lt;pre&gt;
From internal connection:
In QtClass::qtSlot(), x=42
&lt;/pre&gt;



&lt;h4&gt;Utilisation d'un signal Qt connecté à une (ou des) fonction(s) C++ standard par le biais de boost.signals&lt;/h4&gt;


&lt;p&gt;Ici, ça se complique un peu (vraiment un peu, ne vous inquiètez pas ). En effet, nous savons:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;qu'un signal Qt est une méthode protégée&lt;/li&gt;
&lt;li&gt;que le corps d'un signal Qt va associer les informations sur l'objet émetteur (dans le but de permettre l'utilisation de la méthode sender() dans le slot)&lt;/li&gt;
&lt;li&gt;que nous ne pouvons pas connecter de fonctions standard à un signal Qt&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;br /&gt;
Nous allons donc mettre en place ici une méthode impliquant la création d'une classe servant d'adaptateur entre les 2 paradigmes (signaux Qt / boost.signals).&lt;/p&gt;

&lt;pre class=&quot;cpp&quot;&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;class&lt;/span&gt; QtClass : &lt;span style=&quot;color: #0000ff;&quot;&gt;public&lt;/span&gt; QObject
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
Q_OBJECT
&amp;nbsp;
&lt;span style=&quot;color: #0000ff;&quot;&gt;public&lt;/span&gt;:
    &lt;span style=&quot;color: #ff0000;&quot;&gt;// OBLIGATOIRE si on veut connecter un signal boost à un signal Qt: les signaux sont **protégés**&lt;/span&gt;
    &lt;span style=&quot;color: #0000ff;&quot;&gt;void&lt;/span&gt; triggerQtSignalEmission&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;float&lt;/span&gt; x&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
        emit qtSignal&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;x&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
signals:
    &lt;span style=&quot;color: #0000ff;&quot;&gt;void&lt;/span&gt; qtSignal&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;float&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;;
&amp;nbsp;
&lt;span style=&quot;color: #0000ff;&quot;&gt;class&lt;/span&gt; QtSignalToStandardCPPBridge : &lt;span style=&quot;color: #0000ff;&quot;&gt;public&lt;/span&gt; QObject
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
Q_OBJECT
&amp;nbsp;
&lt;span style=&quot;color: #0000ff;&quot;&gt;public&lt;/span&gt;:
    QtSignalToStandardCPPBridge&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;QtClass *qc&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
        connect&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;qc, &lt;span style=&quot;color: #0000ff;&quot;&gt;SIGNAL&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;qtSignal&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;float&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;, &lt;span style=&quot;color: #0000dd;&quot;&gt;this&lt;/span&gt;, SLOT&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;onQtSignalEmitted&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;float&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
    template&amp;lt;typename Signature&amp;gt;
    &lt;span style=&quot;color: #0000ff;&quot;&gt;void&lt;/span&gt; addStandardSlot&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;Signature fun&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
        sig.&lt;span style=&quot;color: #00eeff;&quot;&gt;connect&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;fun&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
&lt;span style=&quot;color: #0000ff;&quot;&gt;private&lt;/span&gt; slots:
    &lt;span style=&quot;color: #0000ff;&quot;&gt;void&lt;/span&gt; onQtSignalEmitted&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;float&lt;/span&gt; x&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
        sig&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;x&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
&lt;span style=&quot;color: #0000ff;&quot;&gt;private&lt;/span&gt;:
    boost::&lt;span style=&quot;color: #00eeff;&quot;&gt;signal&lt;/span&gt;&amp;lt;void &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;float&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&amp;gt;sig;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;;
&amp;nbsp;
&lt;span style=&quot;color: #0000ff;&quot;&gt;class&lt;/span&gt; NonQtClass
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
&lt;span style=&quot;color: #0000ff;&quot;&gt;public&lt;/span&gt;:
    &lt;span style=&quot;color: #ff0000;&quot;&gt;// fonction normale que l'on appelera depuis un signal Qt en passant par un pont&lt;/span&gt;
    &lt;span style=&quot;color: #0000ff;&quot;&gt;void&lt;/span&gt; normalFunction&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;float&lt;/span&gt; x&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
        std::&lt;span style=&quot;color: #0000dd;&quot;&gt;cout&lt;/span&gt; &amp;lt;&amp;lt; &lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot;In NonQtClass::normalFunction(), x=&amp;quot;&lt;/span&gt; &amp;lt;&amp;lt; x &amp;lt;&amp;lt; std::&lt;span style=&quot;color: #00eeff;&quot;&gt;endl&lt;/span&gt;;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
    &lt;span style=&quot;color: #ff0000;&quot;&gt;// Et une autre pour le fun&lt;/span&gt;
    &lt;span style=&quot;color: #0000ff;&quot;&gt;void&lt;/span&gt; displaySquareRoot&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;float&lt;/span&gt; x&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
        std::&lt;span style=&quot;color: #0000dd;&quot;&gt;cout&lt;/span&gt; &amp;lt;&amp;lt; &lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot;In NonQtClass::displaySquareRoot(), sqrt(x)=&amp;quot;&lt;/span&gt; &amp;lt;&amp;lt; std::&lt;span style=&quot;color: #0000dd;&quot;&gt;sqrt&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;x&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; &amp;lt;&amp;lt; std::&lt;span style=&quot;color: #00eeff;&quot;&gt;endl&lt;/span&gt;;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
&lt;span style=&quot;color: #0000ff;&quot;&gt;public&lt;/span&gt;:
    &lt;span style=&quot;color: #0000ff;&quot;&gt;void&lt;/span&gt; QtSignalToStandardFunction&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;QtClass *qc&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
        QtSignalToStandardCPPBridge adapter&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;qc&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
        adapter.&lt;span style=&quot;color: #00eeff;&quot;&gt;addStandardSlot&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;boost::&lt;span style=&quot;color: #00eeff;&quot;&gt;bind&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&amp;amp;NonQtClass::&lt;span style=&quot;color: #00eeff;&quot;&gt;normalFunction&lt;/span&gt;, &lt;span style=&quot;color: #0000dd;&quot;&gt;this&lt;/span&gt;, _1&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
        adapter.&lt;span style=&quot;color: #00eeff;&quot;&gt;addStandardSlot&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;boost::&lt;span style=&quot;color: #00eeff;&quot;&gt;bind&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&amp;amp;NonQtClass::&lt;span style=&quot;color: #00eeff;&quot;&gt;displaySquareRoot&lt;/span&gt;, &lt;span style=&quot;color: #0000dd;&quot;&gt;this&lt;/span&gt;, _1&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
        &lt;span style=&quot;color: #ff0000;&quot;&gt;// On déclenche ici manuellement l'émission du signal Qt&lt;/span&gt;
        qc-&amp;gt;triggerQtSignalEmission&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000dd;&quot;&gt;121&lt;/span&gt;.0f&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;;
&amp;nbsp;
&lt;span style=&quot;color: #0000ff;&quot;&gt;int&lt;/span&gt; main&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;int&lt;/span&gt; argc, &lt;span style=&quot;color: #0000ff;&quot;&gt;char&lt;/span&gt; **argv&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
    NonQtClass nqc;
    QtClass    qc;
&amp;nbsp;
    nqc.&lt;span style=&quot;color: #00eeff;&quot;&gt;QtSignalToStandardFunction&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&amp;amp;qc&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
&amp;nbsp;
    &lt;span style=&quot;color: #0000ff;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #0000dd;&quot;&gt;0&lt;/span&gt;;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Sortie obtenue:&lt;/p&gt;
&lt;pre&gt;
In NonQtClass::normalFunction(), x=121
In NonQtClass::displaySquareRoot(), sqrt(x)=11
&lt;/pre&gt;</description>
    
          <enclosure url="http://doc.qtfr.org/public/2008/qt_boost-signals.zip"
      length="1491" type="application/zip" />
    
    
      </item>
    
  <item>
    <title>Utilisation de PyQt avec Qt 4.4</title>
    <link>http://doc.qtfr.org/post/2008/05/01/Utilisation-de-PyQt-avec-Qt-44</link>
    <guid isPermaLink="false">urn:md5:0e18e4ab0dd062e5d371fd6f4a996b52</guid>
    <pubDate>Thu, 01 May 2008 15:14:00 +0200</pubDate>
    <dc:creator>Visiteur</dc:creator>
        <category>Documentation</category>
        <category>installation</category><category>Linux</category><category>version_PyQt4</category><category>version_Qt4</category>    
    <description>&lt;p&gt;Tool69 vous propose, étape par étape, d'utiliser PyQt avec Qt4.4 RC1.&lt;/p&gt;


&lt;p&gt;&lt;strong&gt;Version&lt;/strong&gt;&amp;nbsp;: Qt4/PyQt4 &lt;br /&gt;
&lt;strong&gt;Auteur&lt;/strong&gt;&amp;nbsp;: &lt;a href=&quot;http://forum.qtfr.org/profile.php?id=428&quot;&gt;Tool69&lt;/a&gt;&lt;/p&gt;    &lt;p&gt;Le document est disponible en 2 formats:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Voir la &lt;a href=&quot;http://kib2.free.fr/Articles/Installation_d%C3%A9taill%C3%A9e_de_PyQt4.4.html&quot;&gt;page sur le blog de l'auteur&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;libre téléchargement en PDF&amp;nbsp;: &lt;a href=&quot;http://doc.qtfr.org/public/2008/Install_Qt44.pdf&quot;&gt;téléchargez&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;</description>
    
          <enclosure url="http://doc.qtfr.org/public/2008/Install_Qt44.pdf"
      length="63431" type="application/pdf" />
    
    
      </item>
    
  <item>
    <title>Introduction aux MVC et création d'un modèle hiérarchique simple</title>
    <link>http://doc.qtfr.org/post/2007/12/16/Creation-dun-modele-hierarchique-simple-base-sur-QAbstractItemModel</link>
    <guid isPermaLink="false">urn:md5:df641f7821f791d36e6b449eb2e1ffd8</guid>
    <pubDate>Sun, 16 Dec 2007 17:02:00 +0100</pubDate>
    <dc:creator>Guid</dc:creator>
        <category>Tutoriels</category>
        <category>class_QAbstractItemModel</category><category>class_QModelIndex</category><category>class_QTreeView</category><category>modèle-vue</category><category>version_Qt4</category>    
    <description>&lt;p&gt;Ce document présente le concept général de MVC, puis s'attarde sur celui de Qt 4 et enfin, une mise en oeuvre simple du &lt;code&gt;QAbstractItemModel&lt;/code&gt; est expliquée en détail et est basée sur sur l'exemple officiel Qt &quot;simpletreemodel&quot;.&lt;/p&gt;


&lt;p&gt;&lt;strong&gt;Version&lt;/strong&gt;&amp;nbsp;: Toutes versions à partir de Qt 4.0 (exemple fait avec C++/Qt 4.3.3)&lt;br /&gt;
&lt;strong&gt;Auteur&lt;/strong&gt;&amp;nbsp;: Guillaume -Guid- DENRY (sur le forum, &lt;a href=&quot;http://forum.qtfr.org/profile.php?id=396&quot;&gt;Azuriel&lt;/a&gt;)&lt;br /&gt;&lt;/p&gt;    &lt;h2&gt;Présentation&lt;/h2&gt;


&lt;p&gt;L'affichage et la manipulation de données est une problèmatique aussi vieille que l'informatique elle-même.
En 1979, une tentative de formalisation de ce domaine aboutit au concept de &lt;acronym title=&quot;Model-View-Controller&quot;&gt;MVC&lt;/acronym&gt; (littéralement Modèle-Vue-Controlleur) qui prend tout d'abord &lt;a href=&quot;http://st-www.cs.uiuc.edu/users/smarch/st-docs/mvc.html&quot; hreflang=&quot;en&quot;&gt;naissance dans le monde smalltalk&lt;/a&gt;, et qui permet de dissocier les données de la présentation ainsi que de la logique de contrôle.
Cette stratégie permet un découpage clair des concepts et de leurs implémentations, mais surtout une factorisation du code; le fameux concept
&lt;a href=&quot;http://en.wikipedia.org/wiki/DRY_code&quot; hreflang=&quot;en&quot;&gt;DRY&lt;/a&gt; cher à Ruby, ainsi, alors que le &lt;em&gt;modèle&lt;/em&gt; est entièrement dévoué à fournir des données et à en accepter, la &lt;em&gt;vue&lt;/em&gt; est uniquement concentrée sur la façon d'afficher les données (c'est la partie émergée de l'iceberg pour l'utilisateur de l'application) tandis que le &lt;em&gt;controlleur&lt;/em&gt;, tel un arbitre, se charge de synchroniser les évènements entre le &lt;em&gt;modèle&lt;/em&gt; et la &lt;em&gt;vue&lt;/em&gt;.&lt;/p&gt;


&lt;p&gt;Qt 4 a choisi d'utiliser ces concepts au sein de plusieurs de ses composants de manipulation et d'affichage de données. Dans la bibliothèque de Trolltech, le C du MVC se retrouve combiné au V pour des raisons de praticité et on parle ainsi de &lt;a href=&quot;http://doc.trolltech.com/4.3/model-view-programming.html&quot; hreflang=&quot;en&quot;&gt;''Modèle/Vue''&lt;/a&gt;.
A ces concepts se voit adjoint celui de &lt;em&gt;delegate&lt;/em&gt; qui définit concrètement la façon dont sont présentées et éditées les données (par exemple via une liste déroulante, une cellule d'édition, etc).&lt;/p&gt;


&lt;p&gt;On trouve plusieurs composants de type &quot;vue&quot;&amp;nbsp;; voici ceux que l'on peut trouver dans la dernière version de Qt 4 au moment où est écrit ce tutoriel (4.3.3)&amp;nbsp;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Le &lt;code&gt;&lt;a href=&quot;http://doc.trolltech.com/4.3/qtableview.html&quot; hreflang=&quot;en&quot;&gt;QTableView&lt;/a&gt;&lt;/code&gt; qui permet d'afficher un ensemble de données sous forme de tableau et sans notion de hiérarchie.&lt;/li&gt;
&lt;li&gt;Le &lt;code&gt;&lt;a href=&quot;http://doc.trolltech.com/4.3/qtreeview.html&quot; hreflang=&quot;en&quot;&gt;QTreeView&lt;/a&gt;&lt;/code&gt; modélise un ensemble de données hiérarchisées sous forme d'arbre.&lt;/li&gt;
&lt;li&gt;Le &lt;code&gt;&lt;a href=&quot;http://doc.trolltech.com/4.3/qlistview.html&quot; hreflang=&quot;en&quot;&gt;QListView&lt;/a&gt;&lt;/code&gt; affiche des données sous forme de liste, exactement comme le mode &quot;liste&quot; d'un explorateur de fichiers.&lt;/li&gt;
&lt;li&gt;Le &lt;code&gt;&lt;a href=&quot;http://doc.trolltech.com/4.3/qcolumnview.html&quot; hreflang=&quot;en&quot;&gt;QColumnView&lt;/a&gt;&lt;/code&gt; qui affiche une succession de QListViews pour afficher une hiérarchie, à l'instar de Finder, le fameux navigateur de fichiers de MacOSX ou de celui de l'Ipod.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Il est à noter que tous ces composants trouvent leurs équivalents déjà affectés de modèles simples et qui peuvent être amplement suffisants pour un usage de base. Si vous cherchez un moyen simple d'afficher des données sans vous soucier d'optimisation, de maintenabilité, de paramétrage fin et si concevoir un système MVC ne vous séduit pas plus que cela, ce tutoriel n'est peut-être pas tout-à-fait indiqué et vous devriez peut-être vous pencher sur les &lt;code&gt;&lt;a href=&quot;http://doc.trolltech.com/4.3/qtablewidget.html&quot; hreflang=&quot;en&quot;&gt;QTableWidget&lt;/a&gt;&lt;/code&gt;/&lt;code&gt;&lt;a href=&quot;http://doc.trolltech.com/4.3/qtreewidget.html&quot; hreflang=&quot;en&quot;&gt;QTreeWidget&lt;/a&gt;&lt;/code&gt;/&lt;code&gt;&lt;a href=&quot;http://doc.trolltech.com/4.3/qlistwidget.html&quot; hreflang=&quot;en&quot;&gt;QListWidget&lt;/a&gt;&lt;/code&gt; qui offrent déjà pas mal de possibilités.&lt;/p&gt;


&lt;p&gt;L'utilisation des modèles dans Qt passe systématiquement par l'héritage d'un des modèles Qt dont l'ancêtre commun est toujours la classe abstraite &lt;code&gt;&lt;a href=&quot;http://doc.trolltech.com/4.3/qabstractitemmodel.html&quot; hreflang=&quot;en&quot;&gt;QAbstractItemModel&lt;/a&gt;&lt;/code&gt;.&lt;br /&gt;
La plupart du temps, vous n'aurez pas besoin d'hériter des vues ainsi que de définir de nouveaux &lt;em&gt;delegates&lt;/em&gt; (ni même vous en soucier pour ces derniers); ceux qui existent déjà suffisent pour la plupart des usages. Néammoins, ce besoin pourra se faire sentir dans certaines circonstances, c'est pourquoi l'écriture d'un delegate particulier et son intégration au sein d'une vue sera abordé dans un autre tutoriel.&lt;/p&gt;


&lt;p&gt;Le concept de MVC est abondamment expliqué dans la documentation officielle Qt et la création d'un modèle simple non hiérarchique est relativement simple à appréhender. Il se peut même que vous n'ayez pas besoin de ce tutoriel car les exemples de Qt en ce qui concerne les modèles/vues sont nombreux et je vous recommande de jeter un oeil aux exemples situés dans le répertoire itemviews du tarball officiel si le parcours d'un tutoriel n'est pas votre tasse de thé.&lt;br /&gt;
Ainsi, tout au long de ce document, nous allons nous concentrer sur le QTreeView et sur la création d'un modèle hiérarchique afin d'expliciter quelques points qui peuvent paraître obscures lorsqu'on s'initie à leur création. Nous tâcherons ainsi d'éclaircir le rôle des diverses méthodes virtuelles à hériter obligatoirement (méthodes abstraites) ou de façon optionnelle afin d'affiner le comportement de notre modèle.&lt;/p&gt;


&lt;h2&gt;Rétro-conception&lt;/h2&gt;


&lt;p&gt;Puisqu'il va falloir indiquer au modèle où trouver nos données et comment se représenter la hiérarchie de celles-ci, il est crucial d'avoir déjà une idée claire et précise de la façon dont nos données sont agencées en mémoire et ce qui les lie les unes aux autres.&lt;br /&gt;
Du côté du modèle, le &lt;code&gt;&lt;a href=&quot;http://doc.trolltech.com/4.3/qmodelindex.html&quot; hreflang=&quot;en&quot;&gt;QModelIndex&lt;/a&gt;&lt;/code&gt; nous offre un moyen simple de mettre en oeuvre les briques élémentaires de la modélisation de nos données.&lt;br /&gt;
Cette classe est le lien entre la donnée élémentaire et le modèle, mais &lt;ins&gt;ne se substitue pas&lt;/ins&gt; à la donnée en elle-même; il est primordial de concevoir une structure de données hiérarchiques interne qui sera utilisée par notre modèle pour créér ses index.&lt;br /&gt;
De façon plus formelle, le &lt;code&gt;QModelIndex&lt;/code&gt; connaît le modèle auquel il appartient, son père&lt;sup&gt;[&lt;a href=&quot;http://doc.qtfr.org/post/2007/12/16/#pnote-171-1&quot; id=&quot;rev-pnote-171-1&quot;&gt;1&lt;/a&gt;]&lt;/sup&gt;, son numéro de ligne (au sein des enfants de ce père, pas le numéro de ligne absolu dans le modèle) ainsi que son numéro de colonne.
Voilà en gros tout dont le modèle a besoin pour construire sa hiérarchie et on expliquera les rôles des autres champs ultérieurement. Pour la suite, pour évoquer le &lt;code&gt;QModelIndex&lt;/code&gt; on parlera simplement d&lt;em&gt;'index&lt;/em&gt;.&lt;/p&gt;


&lt;p&gt;Les structures internes de nos données devront refléter ces propriétés relationnelles, par exemple, il sera indispensable qu'on puisse facilement retrouver le père d'un élément de données. Ranger nos données dans un structure arborescente est donc probablement le meilleur des choix. S'il n'est pas possible de stocker toutes les données en mémoire (typiquement dans le cas d'une base de données), il faudra tout de même pouvoir modéliser ces concepts relationnels &quot;facilement&quot;.&lt;/p&gt;


&lt;p&gt;Comme nous l'avons vu plus haut, concevoir un modèle dans Qt 4, c'est hériter, directement ou indirectement, de la classe &lt;code&gt;QAbstractItemModel&lt;/code&gt; et implémenter un lot de méthodes virtuelles dont certaines sont &lt;em&gt;abstraites&lt;/em&gt; et donc doivent être impérativement héritées sous peine d'erreur de la part du compilateur.&lt;/p&gt;


&lt;p&gt;Ces fonctions abstraites sont&amp;nbsp;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;QModelIndex &lt;a href=&quot;http://doc.trolltech.com/4.3/qabstractitemmodel.html#index&quot; hreflang=&quot;en&quot;&gt;index&lt;/a&gt;(int row, int column, const QModelIndex &amp;amp; parent = QModelIndex())&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;C'est un peu l'&quot;usine à index&quot; du modèle. Ici vont être créés puis renvoyés les index en fonction d'un numéro de ligne, de colonne et d'un index père.
A chaque fois que l'on aura besoin d'un index quelque part, que ce soit dans le modèle ou à l'extérieur de ce modèle, c'est cette méthode qui sera invoquée (à l'exception de la création des index pères qui seront fabriqués par le biais de la fonction &lt;code&gt;parent()&lt;/code&gt;).&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;QModelIndex &lt;a href=&quot;http://doc.trolltech.com/4.3/qabstractitemmodel.html#parent&quot; hreflang=&quot;en&quot;&gt;parent&lt;/a&gt;(const QModelIndex &amp;amp; index)&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Cette méthode est utilisée pour retrouver un index père en fonction de son fils.
Comme nous l'avons vu plus haut dans l'encadré, cette méthode est directement appelée par la méthode &quot;parent()&quot; de chaque QModelIndex appartenant au modèle.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;int &lt;a href=&quot;http://doc.trolltech.com/4.3/qabstractitemmodel.html#rowCount&quot; hreflang=&quot;en&quot;&gt;rowCount&lt;/a&gt;(const QModelIndex &amp;amp; parent = QModelIndex())&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Cette fonction renvoie le nombre de lignes de l'index père passé en paramètre qu'on peut assimiler au nombre d'index enfants de ce père.
Cette méthode peut également se révéler couteuse et dans ce cas, il est parfois utile d'envisager la redéfinition de la méthode &quot;hasChildren()&quot; (cette méthode fait appel à rowCount() dans son implémentation par défaut) qui permet de signaler au modèle qu'un index a des enfants sans pour autant en spécifier combien, et ainsi par exemple afficher un noeud dans la vue qui, impliquera alors un appel à rowCount().&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;int &lt;a href=&quot;http://doc.trolltech.com/4.3/qabstractitemmodel.html#columnCount&quot; hreflang=&quot;en&quot;&gt;columnCount&lt;/a&gt;(const QModelIndex &amp;amp; parent = QModelIndex())&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Cette méthode renvoie le nombre de colonnes des enfants de l'index père passé en paramètre. Dans la plupart des cas, cette méthode renverra un nombre non dépendant du père.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;QVariant &lt;a href=&quot;http://doc.trolltech.com/4.3/qabstractitemmodel.html#data&quot; hreflang=&quot;en&quot;&gt;data&lt;/a&gt;(const QModelIndex &amp;amp; index, int role = Qt::DisplayRole)&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;C'est probablement la fonction la plus sollicitée pendant la vie du modèle; elle permet de connaître les données à afficher dans la vue en fonction d'un index et d'un &lt;em&gt;rôle&lt;/em&gt;.&lt;br /&gt;
Les &lt;em&gt;&lt;a href=&quot;http://doc.trolltech.com/4.3/qt.html#ItemDataRole-enum&quot; hreflang=&quot;en&quot;&gt;rôles&lt;/a&gt;&lt;/em&gt; définissent dans les détails la façon dont une donnée est présentée par les vues associées. On peut par exemple invoquer la méthode &lt;code&gt;data()&lt;/code&gt; pour demander la valeur du texte à afficher par le biais de &lt;code&gt;Qt::DisplayRole&lt;/code&gt; ou alors la couleur de fond de la cellule qui accueuillera le texte avec le paramètre &lt;code&gt;Qt::BackgroundRole&lt;/code&gt;, ou si nécessaire, la police de caractère à utiliser grâce à &lt;code&gt;Qt::FontRole&lt;/code&gt;.&lt;br /&gt;
Les rôles ont été conçus pour être les plus exhaustifs et génériques possibles mais il est possible de les étendre à partir de la valeur &lt;code&gt;Qt::UserRole&lt;/code&gt; qui constitue le premier role &quot;utilisateur&quot;.&lt;br /&gt;
Dans le cas d'une utilisation classique, le rôle essentiel est &lt;code&gt;Qt::DisplayRole&lt;/code&gt; car il concerne directement la donnée (très souvent et en particulier ici du texte) à afficher dans la vue.&lt;br /&gt;
Il faut également garder à l'esprit que &lt;code&gt;data()&lt;/code&gt; étant appelée très fréquemment, il est important de ne pas y trouver de traitements lourds. Typiquement, je ne fais aucun appel aux outils de traduction dans cette méthode, je les déporte dans le constructeur du modèle.&lt;/p&gt;


&lt;p&gt;Puisque Trolltech nous fournit déjà des exemples et des démonstrations de qualité, nous allons appuyer ce tutoriel sur la démo
&lt;a href=&quot;http://doc.trolltech.com/4.3/itemviews-simpletreemodel.html&quot; hreflang=&quot;fr&quot;&gt;simpletreemodel&lt;/a&gt; (sur cette page, vous trouverez également une bonne explication en anglais de cet exemple) disponible dans tout tarball Qt (et dans certains paquets) afin d'expliquer en détail l'implémentation du modèle et les choix effectués.&lt;/p&gt;


&lt;h2&gt;simpletreemodel&lt;/h2&gt;


&lt;h3&gt;Description&lt;/h3&gt;


&lt;p&gt;Cet exemple charge et affiche le contenu dans un arbre (&lt;code&gt;QTreeView&lt;/code&gt;) d'un fichier de type &quot;Sommaire&quot; de livre.
Ce fichier est un ensemble de lignes de texte plus ou moins en retrait par le biais de caractères d'espacement.
Par exemple, une ligne qui commence par 8 espaces et qui précède une ligne qui débute par 4 espaces sera considérée comme &quot;fille&quot; de la ligne précédente.
Chaque ligne de texte est séparée en deux par un ensemble de tabulations, cet ensemble de tabulation permettra de diviser la ligne en deux colonnes dans l'arbre.
Ainsi nous avons donc un arbre à deux colonnes décrit au sein d'un fichier texte et dont voici un extrait&amp;nbsp;:&lt;/p&gt;

&lt;pre&gt;
Form Editing Mode                       How to edit a form in Qt Designer
    Managing Forms                      Loading and saving forms
...
    Layouts                             Objects that arrange widgets on a form
        Applying and Breaking Layouts   Managing widgets in layouts
&lt;/pre&gt;


&lt;h3&gt;Exécution&lt;/h3&gt;


&lt;p&gt;Au lancement du programme, un modèle (implémenté dans treemodel.h/treemodel.cpp) est créé avec en paramètre le texte du fichier &quot;default.txt&quot; chargé pour l'occasion. Ce texte est &quot;parsé&quot; (analysé et stocké dans une structure de données) pendant la construction du modèle, ce qui permettra son utilisation immédiate plus tard sans autre forme d'initialisation.
Puis, un &lt;code&gt;QTreeView&lt;/code&gt; est également créé et on lui affecte le modèle.
On attribue un titre à cet arbre puis il est affiché et la boucle d'évènements est lancée; le programme est réellement visuellement disponible à ce moment là et nous pouvons voir à l'écran le &lt;code&gt;QTreeView&lt;/code&gt; en action et le manipuler à notre guise.&lt;/p&gt;


&lt;h3&gt;Analyse&lt;/h3&gt;


&lt;h4&gt;Le stockage des données&lt;/h4&gt;


&lt;p&gt;Examinons tout d'abord le contenu de treeitem.h/.cpp.
La classe &lt;code&gt;TreeItem&lt;/code&gt; est conçue pour stocker une hiérarchie de données. Voici ses caractéristiques&amp;nbsp;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;parentItem&lt;/code&gt; pointe vers son élément père.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;childItems&lt;/code&gt; est une liste de pointeurs vers les fils de cet élément.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;itemData&lt;/code&gt; contient les données de l'élément sous forme de liste de QVariant (qui est le type générique de Qt, voir la documentation).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Pour cet exemple, l'auteur aurait pu se contenter pour &lt;code&gt;itemData&lt;/code&gt; d'une liste de &lt;code&gt;QString&lt;/code&gt;, mais le &lt;code&gt;QVariant&lt;/code&gt; permet d'imaginer un enrichissement de l'exemple afin de pouvoir stocker et afficher des types de données hétéroclytes au sein de la même liste. Il permet surtout d'être directement renvoyé par la méthode &lt;code&gt;data()&lt;/code&gt; du modèle sans aucune conversion comme nous le verrons plus tard.
A l'image d'une liste chaînée, l'arbre entier est accessible par sa racine et lorsqu'on détruit un &lt;code&gt;TreeItem&lt;/code&gt;, ses enfants sont également détruits. Notez à ce titre l'utilisation de &lt;code&gt;qDeleteAll()&lt;/code&gt;, fonction bien pratique qui permet de détruire tous les objets pointés stockés dans une structure de données Qt (QList, QVector, etc).&lt;/p&gt;


&lt;p&gt;Voilà qui permet de conclure sur cette classe &quot;jumelle&quot; à la hiérarchie des index et qui servira de conteneur de données librement consultable par le modèle de notre vue.&lt;/p&gt;


&lt;h4&gt;Le modèle&lt;/h4&gt;


&lt;p&gt;Intéressons-nous maintenant à la classe &lt;code&gt;TreeModel&lt;/code&gt; définie dans treemodel.h/.cpp.&lt;/p&gt;


&lt;p&gt;La méthode &lt;code&gt;setupModelData()&lt;/code&gt; contient le code le plus complexe de l'exemple :-), il analyse le texte en paramètre et en déduit une hiérarchie de TreeItems qu'il lie au noeud parent passé en paramètre. Cette fonction est appelée uniquement dans le constructeur avec &lt;code&gt;rootData&lt;/code&gt; préalablement créé. Ce noeud racine sera le point d'accès à l'arbre de données pour le modèle.&lt;/p&gt;


&lt;p&gt;En dehors de &lt;code&gt;setupModelData()&lt;/code&gt;, le reste des méthodes présentes sont des éléments hérités appartenant au &lt;code&gt;QAbstractItemModel&lt;/code&gt;&amp;nbsp;:&lt;/p&gt;


&lt;h5&gt;La méthode &lt;code&gt;parent()&lt;/code&gt;&lt;/h5&gt;

&lt;pre class=&quot;cpp&quot;&gt;QModelIndex TreeModel::&lt;span style=&quot;color: #00eeff;&quot;&gt;parent&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;const&lt;/span&gt; QModelIndex &amp;amp;index&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;const&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span style=&quot;color: #0000ff;&quot;&gt;if&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;!index.&lt;span style=&quot;color: #00eeff;&quot;&gt;isValid&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
        &lt;span style=&quot;color: #0000ff;&quot;&gt;return&lt;/span&gt; QModelIndex&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;/pre&gt;


&lt;p&gt;Le but de la méthode &lt;code&gt;parent()&lt;/code&gt; est de créer et renvoyer un &lt;code&gt;QModelIndex&lt;/code&gt; correspondant au père du &lt;code&gt;QModelIndex&lt;/code&gt; en paramètre.
Si l'index en paramètre est considéré comme orphelin dans l'arbre, alors il convient de renvoyer un index invalide.
Dans notre cas, un index racine est un index correspondant à un &lt;code&gt;TreeItem&lt;/code&gt; dont le père est &lt;code&gt;rootData&lt;/code&gt;.
&lt;code&gt;rootData&lt;/code&gt; est le seul élément dans tout l'arbre des &lt;code&gt;TreeItem&lt;/code&gt; qui n'a aucun &lt;code&gt;QModelIndex&lt;/code&gt; correspondant, il sert juste de père ultime référent et donc, les vrais éléments racines de l'arbre affichés à l'écran sont ses enfants directs.
&lt;code&gt;parent()&lt;/code&gt; est également une méthode publique. Rien que pour cette raison il est important de tester le cas où l'index en paramètre est invalide.
Le père d'un index invalide est donc naturellement ... un index invalide, créé par le biais du constructeur vide du &lt;code&gt;QModelIndex&lt;/code&gt;.&lt;/p&gt;

&lt;pre class=&quot;cpp&quot;&gt;TreeItem *childItem = static_cast&amp;lt;TreeItem*&amp;gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;index.&lt;span style=&quot;color: #00eeff;&quot;&gt;internalPointer&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
    TreeItem *parentItem = childItem-&amp;gt;parent&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;/pre&gt;


&lt;p&gt;&lt;code&gt;internalPointer&lt;/code&gt; est une variable qui fait le lien entre l'index et la donnée. Chaque index du modèle sera donc lié à un &lt;code&gt;TreeItem&lt;/code&gt; cette liaison est faite à deux endroits du modèle; la méthode &lt;code&gt;index()&lt;/code&gt; et la méthode &lt;code&gt;parent()&lt;/code&gt;.
La première instruction se contente donc de récupérer le &lt;code&gt;TreeItem&lt;/code&gt; associé à l'index, en passant par un &lt;code&gt;static_cast&lt;/code&gt;, plus rapide qu'un &lt;code&gt;dynamic_cast&lt;/code&gt; et suffisant ici.
Il existe un autre moyen de lier une donnée à un index, &lt;code&gt;internalId&lt;/code&gt; qui est une autre propriété du &lt;code&gt;QModelIndex&lt;/code&gt;, utile dans les cas où la donnée serait accessible via un identificateur entier et non un pointeur. (on peut imaginer une clef entière dans une base de donnée, par exemple).
La seconde instruction stocke le père du &lt;code&gt;TreeItem&lt;/code&gt; prédédemment extrait dans &lt;code&gt;parentItem&lt;/code&gt;.&lt;/p&gt;

&lt;pre class=&quot;cpp&quot;&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;if&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;parentItem == rootItem&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
        &lt;span style=&quot;color: #0000ff;&quot;&gt;return&lt;/span&gt; QModelIndex&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;/pre&gt;


&lt;p&gt;Nous avons vu que chaque &lt;code&gt;TreeItem&lt;/code&gt; pointe vers son père, si l'élément père est &lt;code&gt;rootItem&lt;/code&gt;, alors on considère du point de vue du modèle que l'index correspondant est un noeud racine et donc, on renvoie un &lt;code&gt;QModelIndex&lt;/code&gt; invalide.&lt;/p&gt;

&lt;pre class=&quot;cpp&quot;&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;return&lt;/span&gt; createIndex&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;parentItem-&amp;gt;row&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;, &lt;span style=&quot;color: #0000dd;&quot;&gt;0&lt;/span&gt;, parentItem&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;&lt;code&gt;createIndex()&lt;/code&gt;&lt;sup&gt;[&lt;a href=&quot;http://doc.qtfr.org/post/2007/12/16/#pnote-171-2&quot; id=&quot;rev-pnote-171-2&quot;&gt;2&lt;/a&gt;]&lt;/sup&gt; est une méthode qui permet de créer en une instruction un &lt;code&gt;QModelIndex&lt;/code&gt; attaché au modèle.&lt;/p&gt;


&lt;p&gt;La méthode &lt;code&gt;row()&lt;/code&gt; du TreeItem renvoie le numéro de ligne de l'élément au sein de ses frères et c'est exactement ce que &lt;code&gt;createIndex&lt;/code&gt; attend comme premier paramètre.
0 est passé comme numéro de colonne car le père d'un index est par convention toujours de colonne 0 dans un système hiérarchique conventionnel.
Et enfin, &lt;code&gt;parentItem&lt;/code&gt; est passé en tant que comme pointeur interne, c'est un des deux endroits dans le code où l'on associe un &lt;code&gt;TreeItem&lt;/code&gt; à son &lt;code&gt;QModelIndex&lt;/code&gt;.&lt;/p&gt;


&lt;h5&gt;La méthode &lt;code&gt;index()&lt;/code&gt;&lt;/h5&gt;

&lt;pre class=&quot;cpp&quot;&gt;QModelIndex TreeModel::&lt;span style=&quot;color: #00eeff;&quot;&gt;index&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;int&lt;/span&gt; row, &lt;span style=&quot;color: #0000ff;&quot;&gt;int&lt;/span&gt; column, &lt;span style=&quot;color: #0000ff;&quot;&gt;const&lt;/span&gt; QModelIndex &amp;amp;parent&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;const&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span style=&quot;color: #0000ff;&quot;&gt;if&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;!hasIndex&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;row, column, parent&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
        &lt;span style=&quot;color: #0000ff;&quot;&gt;return&lt;/span&gt; QModelIndex&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;/pre&gt;


&lt;p&gt;La méthode &lt;code&gt;index()&lt;/code&gt; est publique. Il convient donc de tester ses paramètres afin de résoudre les cas invalides.
En particulier, nous aimerions savoir si les paramètres &lt;code&gt;row&lt;/code&gt; et &lt;code&gt;column&lt;/code&gt; ne sortent pas des limites du modèle et heureusement, pour le savoir, il existe la fonction &lt;code&gt;hasIndex()&lt;/code&gt; qui nous renseigne à ce sujet. La documentation étant peu locace pour cette fonction, c'est dans les sources de Qt que nous allons trouver son rôle précis; cette méthode renvoie vrai si et seulement si les paramètres &lt;code&gt;row&lt;/code&gt; et &lt;code&gt;column&lt;/code&gt; sont compris entre 0 et le nombre maximum de lignes et de colonnes du parent passé en paramètre.&lt;/p&gt;

&lt;pre class=&quot;cpp&quot;&gt;TreeItem *parentItem;
&amp;nbsp;
    &lt;span style=&quot;color: #0000ff;&quot;&gt;if&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;!parent.&lt;span style=&quot;color: #00eeff;&quot;&gt;isValid&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
        parentItem = rootItem;
    &lt;span style=&quot;color: #0000ff;&quot;&gt;else&lt;/span&gt;
        parentItem = static_cast&amp;lt;TreeItem*&amp;gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;parent.&lt;span style=&quot;color: #00eeff;&quot;&gt;internalPointer&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;/pre&gt;


&lt;p&gt;Ici nous avons besoin de récupérer l'élément de type &lt;code&gt;TreeItem&lt;/code&gt; correspondant à l'index que nous allons renvoyer.
Nous savons que si le paramètre &lt;code&gt;parent&lt;/code&gt; est valide, alors il aura été créé avec &lt;code&gt;parent()&lt;/code&gt; et possèdera donc en pointeur interne sur son &lt;code&gt;TreeItem&lt;/code&gt; &quot;jumeau&quot; et, dans le cas où &lt;code&gt;parent&lt;/code&gt; est invalide, c'est &lt;code&gt;rootItem&lt;/code&gt; qui jouera ce rôle.&lt;/p&gt;

&lt;pre class=&quot;cpp&quot;&gt;TreeItem *childItem = parentItem-&amp;gt;child&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;row&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
    &lt;span style=&quot;color: #0000ff;&quot;&gt;if&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;childItem&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
        &lt;span style=&quot;color: #0000ff;&quot;&gt;return&lt;/span&gt; createIndex&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;row, column, childItem&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
    &lt;span style=&quot;color: #0000ff;&quot;&gt;else&lt;/span&gt;
        &lt;span style=&quot;color: #0000ff;&quot;&gt;return&lt;/span&gt; QModelIndex&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Maintenant que nous avons l'élément père ainsi que le numéro de ligne du fils, il est trivial d'en déduire l'élément fils avec la méthode &lt;code&gt;child()&lt;/code&gt;. Par prudence, le retour de cette méthode est testé et &lt;code&gt;createIndex()&lt;/code&gt; est à nouveau invoqué puis retourné par la fonction.&lt;/p&gt;


&lt;h5&gt;La méthode &lt;code&gt;data()&lt;/code&gt;&lt;/h5&gt;

&lt;pre class=&quot;cpp&quot;&gt;QVariant TreeModel::&lt;span style=&quot;color: #00eeff;&quot;&gt;data&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;const&lt;/span&gt; QModelIndex &amp;amp;index, &lt;span style=&quot;color: #0000ff;&quot;&gt;int&lt;/span&gt; role&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;const&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span style=&quot;color: #0000ff;&quot;&gt;if&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;!index.&lt;span style=&quot;color: #00eeff;&quot;&gt;isValid&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
        &lt;span style=&quot;color: #0000ff;&quot;&gt;return&lt;/span&gt; QVariant&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;/pre&gt;


&lt;p&gt;Nous retrouvons le même début de scénario que pour les deux méthodes précédemment analysées, &lt;code&gt;data()&lt;/code&gt; étant public, la validité de &lt;code&gt;index&lt;/code&gt; est éprouvée et un QVariant() invalide est envoyé le cas échéant.&lt;/p&gt;

&lt;pre class=&quot;cpp&quot;&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;if&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;role != Qt::&lt;span style=&quot;color: #00eeff;&quot;&gt;DisplayRole&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
        &lt;span style=&quot;color: #0000ff;&quot;&gt;return&lt;/span&gt; QVariant&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;/pre&gt;


&lt;p&gt;Dans cette démo, la vue ne sollicitera que le texte pour son affichage, et donc, tous les rôles autre que &lt;code&gt;Qt::DisplayRole&lt;/code&gt; sont écartés. Pour se faire, un &lt;code&gt;QVariant()&lt;/code&gt; invalide est renvoyé et signifie à l'appelant qu'il fait ce qu'il veut: pour un &lt;code&gt;QTreeView&lt;/code&gt;, ça sera par exemple d'afficher la couleur de fond par défaut du composant dans le cas du &lt;code&gt;Qt::BackgroundRole&lt;/code&gt;.&lt;/p&gt;

&lt;pre class=&quot;cpp&quot;&gt;TreeItem *item = static_cast&amp;lt;TreeItem*&amp;gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;index.&lt;span style=&quot;color: #00eeff;&quot;&gt;internalPointer&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
&amp;nbsp;
    &lt;span style=&quot;color: #0000ff;&quot;&gt;return&lt;/span&gt; item-&amp;gt;data&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;index.&lt;span style=&quot;color: #00eeff;&quot;&gt;column&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Nous avons besoin de retrouver l'élément correspondant à l'index, puis de renvoyer la donnée correspondant à son numéro de colonne.
La méthode &lt;code&gt;data()&lt;/code&gt; renvoie un &lt;code&gt;QVariant&lt;/code&gt; et nous voyons ici l'utilité sémantique d'avoir stocké une liste de &lt;code&gt;QVariant&lt;/code&gt; au sein du &lt;code&gt;TreeItem&lt;/code&gt; plutôt qu'une liste de &lt;code&gt;QString&lt;/code&gt;, même si en l'occurrence, le renvoi d'un &lt;code&gt;QString&lt;/code&gt; aurait été possible grace à la construction implicite du C++.&lt;/p&gt;


&lt;h5&gt;La méthode &lt;code&gt;rowCount()&lt;/code&gt;&lt;/h5&gt;

&lt;pre class=&quot;cpp&quot;&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;int&lt;/span&gt; TreeModel::&lt;span style=&quot;color: #00eeff;&quot;&gt;rowCount&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;const&lt;/span&gt; QModelIndex &amp;amp;parent&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;const&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
    TreeItem *parentItem;
    &lt;span style=&quot;color: #0000ff;&quot;&gt;if&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;parent.&lt;span style=&quot;color: #00eeff;&quot;&gt;column&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; &amp;gt; &lt;span style=&quot;color: #0000dd;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
        &lt;span style=&quot;color: #0000ff;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #0000dd;&quot;&gt;0&lt;/span&gt;;&lt;/pre&gt;


&lt;p&gt;Nous avons vu plus haut que le père d'un index a par convention son numéro de colonne égal à 0 dans un cas de hiérarchie classique.
De la même façon, tout index de colonne strictement supérieur à 0 ne possède aucun fils; ce rôle est dévolu à l'index de colonne 0.&lt;/p&gt;

&lt;pre class=&quot;cpp&quot;&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;if&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;!parent.&lt;span style=&quot;color: #00eeff;&quot;&gt;isValid&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
        parentItem = rootItem;
    &lt;span style=&quot;color: #0000ff;&quot;&gt;else&lt;/span&gt;
        parentItem = static_cast&amp;lt;TreeItem*&amp;gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;parent.&lt;span style=&quot;color: #00eeff;&quot;&gt;internalPointer&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
&amp;nbsp;
    &lt;span style=&quot;color: #0000ff;&quot;&gt;return&lt;/span&gt; parentItem-&amp;gt;childCount&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Comme pour la fonction &lt;code&gt;data()&lt;/code&gt;, il nous faut extraire le &lt;code&gt;TreeItem&lt;/code&gt; correspondant à l'index &lt;code&gt;parent&lt;/code&gt;.
L'appel de &lt;code&gt;rowCount()&lt;/code&gt; avec un index invalide signifie que l'utilisateur souhaite le nombre de noeuds racines, dans ce cas, &lt;code&gt;rootItem&lt;/code&gt; jouera le rôle de l'élément père.
Le nombre d'enfants de l'élément père est alors renvoyé.&lt;/p&gt;


&lt;h5&gt;La méthode &lt;code&gt;columnCount()&lt;/code&gt;&lt;/h5&gt;

&lt;pre class=&quot;cpp&quot;&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;int&lt;/span&gt; TreeModel::&lt;span style=&quot;color: #00eeff;&quot;&gt;columnCount&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;const&lt;/span&gt; QModelIndex &amp;amp;parent&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;const&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span style=&quot;color: #0000ff;&quot;&gt;if&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;parent.&lt;span style=&quot;color: #00eeff;&quot;&gt;isValid&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
        &lt;span style=&quot;color: #0000ff;&quot;&gt;return&lt;/span&gt; static_cast&amp;lt;TreeItem*&amp;gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;parent.&lt;span style=&quot;color: #00eeff;&quot;&gt;internalPointer&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;-&amp;gt;columnCount&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
    &lt;span style=&quot;color: #0000ff;&quot;&gt;else&lt;/span&gt;
        &lt;span style=&quot;color: #0000ff;&quot;&gt;return&lt;/span&gt; rootItem-&amp;gt;columnCount&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Elle est similaire à la méthode &lt;code&gt;rowCount()&lt;/code&gt; si ce n'est une difficulté en moins puisque que l'on peut se contenter de renvoyer directement le nombre de colonnes de l'élément attaché à l'index.&lt;/p&gt;


&lt;h5&gt;Les méthodes &lt;code&gt;flags()&lt;/code&gt; et &lt;code&gt;headerData()&lt;/code&gt;&lt;/h5&gt;

&lt;pre class=&quot;cpp&quot;&gt;Qt::&lt;span style=&quot;color: #00eeff;&quot;&gt;ItemFlags&lt;/span&gt; TreeModel::&lt;span style=&quot;color: #00eeff;&quot;&gt;flags&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;const&lt;/span&gt; QModelIndex &amp;amp;index&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;const&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span style=&quot;color: #0000ff;&quot;&gt;if&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;!index.&lt;span style=&quot;color: #00eeff;&quot;&gt;isValid&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
        &lt;span style=&quot;color: #0000ff;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #0000dd;&quot;&gt;0&lt;/span&gt;;
&amp;nbsp;
    &lt;span style=&quot;color: #0000ff;&quot;&gt;return&lt;/span&gt; Qt::&lt;span style=&quot;color: #00eeff;&quot;&gt;ItemIsEnabled&lt;/span&gt; | Qt::&lt;span style=&quot;color: #00eeff;&quot;&gt;ItemIsSelectable&lt;/span&gt;;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;C'est dans cette fonction que nous allons définir finement le comportement du modèle.
Nous lui précisons ici que nous souhaitons pouvoir intéragir avec l'index en paramètre (&lt;code&gt;Qt::ItemIsEnabled&lt;/code&gt;), ainsi que le sélectionner (&lt;code&gt;Qt::ItemIsSelectable&lt;/code&gt;).&lt;/p&gt;

&lt;pre class=&quot;cpp&quot;&gt;QVariant TreeModel::&lt;span style=&quot;color: #00eeff;&quot;&gt;headerData&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;int&lt;/span&gt; section, Qt::&lt;span style=&quot;color: #00eeff;&quot;&gt;Orientation&lt;/span&gt; orientation,
                               &lt;span style=&quot;color: #0000ff;&quot;&gt;int&lt;/span&gt; role&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;const&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span style=&quot;color: #0000ff;&quot;&gt;if&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;orientation == Qt::&lt;span style=&quot;color: #00eeff;&quot;&gt;Horizontal&lt;/span&gt; &amp;amp;&amp;amp; role == Qt::&lt;span style=&quot;color: #00eeff;&quot;&gt;DisplayRole&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
        &lt;span style=&quot;color: #0000ff;&quot;&gt;return&lt;/span&gt; rootItem-&amp;gt;data&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;section&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
&amp;nbsp;
    &lt;span style=&quot;color: #0000ff;&quot;&gt;return&lt;/span&gt; QVariant&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;&lt;code&gt;headerData()&lt;/code&gt; est similaire à la fonction &lt;code&gt;data()&lt;/code&gt; si ce n'est qu'elle concerne uniquement les entêtes des lignes et colonnes. Pour notre exemple, seule l'entête des colonnes est affichée et nous utilisons donc à cette fin les valeurs de &lt;code&gt;rootItem&lt;/code&gt; uniquement dans le cas où l'orientation est &lt;code&gt;Qt::Horizontal&lt;/code&gt;.&lt;/p&gt;


&lt;h2&gt;Conclusion&lt;/h2&gt;


&lt;p&gt;Pour des raisons de simplicité, j'ai jugé utile de limiter ce tutoriel à l'analyse d'un exemple simple et en lecture seule et de nombreux aspects de la manipulation des modèles/vue n'y sont pas abordés.
Par exemple, lorsqu'on veut modifier les données internes, comment avertir le modèle -et donc la vue- que les données ont changées&amp;nbsp;? Comment rendre le modèle éditable; doit-on utiliser les méthodes d'insertions et de suppression du modèle ou un système alternatif&amp;nbsp;? L'édition des données est trop basique, je voudrais la changer, comment faire&amp;nbsp;? Comment construire un système de recherche au sein d'un modèle&amp;nbsp;? Comment gérer les types Mime ainsi que le drag'n'drop&amp;nbsp;?
Ces questions seront abordées dans un tutoriel plus avancé.&lt;/p&gt;
&lt;div class=&quot;footnotes&quot;&gt;&lt;h4&gt;Notes&lt;/h4&gt;
&lt;p&gt;[&lt;a href=&quot;http://doc.qtfr.org/post/2007/12/16/#rev-pnote-171-1&quot; id=&quot;pnote-171-1&quot;&gt;1&lt;/a&gt;] Si les valeurs renvoyées par &lt;code&gt;row()&lt;/code&gt;, &lt;code&gt;column()&lt;/code&gt; et &lt;code&gt;model()&lt;/code&gt; appartiennent bien en interne au &lt;code&gt;QModelIndex&lt;/code&gt; par le biais de champs privés, le champ &lt;code&gt;parent()&lt;/code&gt; est en revanche une invocation directe de la méthode virtuelle pure &lt;code&gt;parent()&lt;/code&gt; du modèle de l'index. Ceci peut mettre en lumière le rôle de la fonction &lt;code&gt;parent()&lt;/code&gt; du modèle et son implication.&lt;/p&gt;
&lt;p&gt;[&lt;a href=&quot;http://doc.qtfr.org/post/2007/12/16/#rev-pnote-171-2&quot; id=&quot;pnote-171-2&quot;&gt;2&lt;/a&gt;] Il existe un constructeur du &lt;code&gt;QModelIndex&lt;/code&gt; qui accepte à peu près les mêmes paramètres que &lt;code&gt;createIndex()&lt;/code&gt; et qui aurait pu prendre sa place mais pour des raisons d'intégrité et de cohérence (pour ne jamais avoir d'index sans modèle référent), ce constructeur est privé; le seul moyen de créer un index valide est de passer par le modèle et donc par une des déclinaisons de &lt;code&gt;createIndex()&lt;/code&gt;.&lt;/p&gt;&lt;/div&gt;
</description>
    
    
    
      </item>
    
  <item>
    <title>Réseau avec Qt4</title>
    <link>http://doc.qtfr.org/post/2007/06/01/Reseau-avec-Qt4</link>
    <guid isPermaLink="false">urn:md5:03e6144a76a6712010e2ba373f2471b5</guid>
    <pubDate>Fri, 01 Jun 2007 22:36:00 +0200</pubDate>
    <dc:creator>Visiteur</dc:creator>
        <category>Tutoriels</category>
        <category>class_QFtp</category><category>class_QHttp</category><category>class_QTcpSocket</category><category>réseau</category><category>version_Qt4</category>    
    <description>&lt;ul&gt;
&lt;li&gt;Comment utiliser les classes réseaux de Qt&amp;nbsp;?&lt;/li&gt;
&lt;li&gt;Comment faire un client/serveur TCP&amp;nbsp;?&lt;/li&gt;
&lt;li&gt;Comment faire un client FTP&amp;nbsp;?&lt;/li&gt;
&lt;li&gt;Comment faire un client HTTP&amp;nbsp;?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Ce document présente différentes communications réseaux possibles en utilisant les classes de Qt&amp;nbsp;: TCP, FTP et HTTP.&lt;/p&gt;


&lt;p&gt;&lt;strong&gt;Version&lt;/strong&gt;&amp;nbsp;: Qt4 &lt;br /&gt;
&lt;strong&gt;Auteur&lt;/strong&gt;&amp;nbsp;: &lt;a href=&quot;http://forum.qtfr.org/profile.php?id=295&quot;&gt;rocsan&lt;/a&gt;&lt;br /&gt;&lt;/p&gt;    &lt;p&gt;Le document est disponible en &lt;strong&gt;libre téléchargement en PDF&lt;/strong&gt;&amp;nbsp;: &lt;a href=&quot;http://doc.qtfr.org/public/2007/reseau-avec-qt4.pdf&quot;&gt;téléchargez&lt;/a&gt;.&lt;/p&gt;


&lt;p&gt;Il présente les différentes façons d'effectuer des communications réseaux avec Qt.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Création d’un client TCP&lt;/li&gt;
&lt;li&gt;Création d’un serveur TCP&lt;/li&gt;
&lt;li&gt;Création d’un client FTP&lt;/li&gt;
&lt;li&gt;Création d’un client HTTP&lt;/li&gt;
&lt;/ul&gt;</description>
    
          <enclosure url="http://doc.qtfr.org/public/2007/reseau-avec-qt4.pdf"
      length="371704" type="application/pdf" />
    
    
      </item>
    
  <item>
    <title>XML avec Qt4</title>
    <link>http://doc.qtfr.org/post/2007/05/17/XML-avec-Qt4</link>
    <guid isPermaLink="false">urn:md5:f02e91fb0d584fdc0a825d3561754765</guid>
    <pubDate>Sun, 27 May 2007 21:07:00 +0200</pubDate>
    <dc:creator>Visiteur</dc:creator>
        <category>Tutoriels</category>
        <category>class_QDomDocument</category><category>class_QDomElement</category><category>class_QXmlDefaultHandler</category><category>version_Qt4</category><category>xml</category>    
    <description>&lt;ul&gt;
&lt;li&gt;Comment lire ou écrire un fichier XML&amp;nbsp;?&lt;/li&gt;
&lt;li&gt;Comment utiliser les méthodes DOM et SAX&amp;nbsp;?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Ce document présente l'utilisation des méthodes &lt;a href=&quot;http://fr.wikipedia.org/wiki/Document_Object_Model&quot; hreflang=&quot;fr&quot;&gt;DOM&lt;/a&gt; et &lt;a href=&quot;http://fr.wikipedia.org/wiki/SAX&quot; hreflang=&quot;fr&quot;&gt;SAX&lt;/a&gt; avec Qt pour la lecture d'un fichier &lt;a href=&quot;http://fr.wikipedia.org/wiki/XML&quot; hreflang=&quot;fr&quot;&gt;XML&lt;/a&gt;.&lt;/p&gt;


&lt;p&gt;&lt;strong&gt;Version&lt;/strong&gt;&amp;nbsp;: Qt4 &lt;br /&gt;
&lt;strong&gt;Auteur&lt;/strong&gt;&amp;nbsp;: &lt;a href=&quot;http://forum.qtfr.org/profile.php?id=295&quot;&gt;rocsan&lt;/a&gt;&lt;br /&gt;&lt;/p&gt;    &lt;p&gt;Le document est disponible en &lt;strong&gt;libre téléchargement en PDF&lt;/strong&gt;&amp;nbsp;: &lt;a href=&quot;http://doc.qtfr.org/public/2007/xml-avec-qt4.pdf&quot;&gt;téléchargez&lt;/a&gt;.&lt;/p&gt;


&lt;p&gt;Il détaille l'utilisation des méthodes DOM et SAX pour la lecture de fichier XML.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Présentation&lt;/li&gt;
&lt;li&gt;Ecriture d'un document XML avec la méthode DOM
&lt;ul&gt;
&lt;li&gt;Introduction à DOM&lt;/li&gt;
&lt;li&gt;Présentation de l'application&lt;/li&gt;
&lt;li&gt;Codage&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Lecture d'un document XML avec la méthode DOM
&lt;ul&gt;
&lt;li&gt;Présentation de l'application&lt;/li&gt;
&lt;li&gt;Codage&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Lecture d'un document XML avec la méthode SAX
&lt;ul&gt;
&lt;li&gt;Introduction à SAX&lt;/li&gt;
&lt;li&gt;Présentation de l'application&lt;/li&gt;
&lt;li&gt;Codage&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;/ul&gt;</description>
    
          <enclosure url="http://doc.qtfr.org/public/2007/xml-avec-qt4.pdf"
      length="307672" type="application/pdf" />
    
    
      </item>
    
  <item>
    <title>Dessiner avec Qt4</title>
    <link>http://doc.qtfr.org/post/2007/04/24/Dessiner-avec-Qt4</link>
    <guid isPermaLink="false">urn:md5:a363bb36b598957e1235db27a9b40129</guid>
    <pubDate>Tue, 24 Apr 2007 11:02:00 +0200</pubDate>
    <dc:creator>Visiteur</dc:creator>
        <category>Documentation</category>
        <category>class_QPaintDevice</category><category>class_QPaintEngine</category><category>class_QPainter</category><category>dessin</category><category>version_Qt4</category>    
    <description>&lt;ul&gt;
&lt;li&gt;Quelles sont les primitives de dessin de Qt4&amp;nbsp;?&lt;/li&gt;
&lt;li&gt;Où peut-on utiliser QPainter&amp;nbsp;?&lt;/li&gt;
&lt;li&gt;Quels sont les réglages et personnalisations possibles lors d'un dessin&amp;nbsp;?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Ce document offre un excellent aide-mémoire pour tous ceux qui ont besoin d'utiliser le &lt;a href=&quot;http://doc.trolltech.com/4.3/paintsystem.html&quot; hreflang=&quot;en&quot;&gt;système de dessin de Qt&lt;/a&gt;. Basé sur la version 4.3, un grand nombre de fonctions et explications restent néanmoins valables pour des version inférieures de Qt (même Qt3).&lt;/p&gt;


&lt;p&gt;&lt;strong&gt;Version&lt;/strong&gt;&amp;nbsp;: Qt4 &lt;br /&gt;
&lt;strong&gt;Auteur&lt;/strong&gt;&amp;nbsp;: Véronique Lefrere&lt;/p&gt;    &lt;p&gt;Le document est disponible en &lt;strong&gt;libre téléchargement en PDF&lt;/strong&gt;&amp;nbsp;: &lt;a href=&quot;http://doc.qtfr.org/public/2007/dessiner-avec-qt4.pdf&quot;&gt;téléchargez&lt;/a&gt;.&lt;/p&gt;


&lt;p&gt;Il couvre tous les aspects du dessin (primitives, &lt;code&gt;QPainter&lt;/code&gt;, personnalisation...)&amp;nbsp;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Dessiner quoi&amp;nbsp;?
&lt;ul&gt;
&lt;li&gt;Un (ou plusieurs) point(s) sur un plan donné&lt;/li&gt;
&lt;li&gt;Des segments&lt;/li&gt;
&lt;li&gt;Un polygone&lt;/li&gt;
&lt;li&gt;Un rectangle&lt;/li&gt;
&lt;li&gt;Un rectangles (angles arrondis)&lt;/li&gt;
&lt;li&gt;Une Ellipse&lt;/li&gt;
&lt;li&gt;Un Arc de cercle&lt;/li&gt;
&lt;li&gt;Une forme circulaire&lt;/li&gt;
&lt;li&gt;Une corde&lt;/li&gt;
&lt;li&gt;Un chemin&lt;/li&gt;
&lt;li&gt;Une région ou une zone&lt;/li&gt;
&lt;li&gt;Du texte&lt;/li&gt;
&lt;li&gt;Une pixmap ou une image&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Dessiner sur quoi?
&lt;ul&gt;
&lt;li&gt;Le support&lt;/li&gt;
&lt;li&gt;La region&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Dessiner comment&amp;nbsp;?
&lt;ul&gt;
&lt;li&gt;Les pré-réglages de dessin&lt;/li&gt;
&lt;li&gt;La transparence&lt;/li&gt;
&lt;li&gt;L’Anti-crènelage (anti-aliasing)&lt;/li&gt;
&lt;li&gt;Les lignes et contours&lt;/li&gt;
&lt;li&gt;Le remplissage&lt;/li&gt;
&lt;li&gt;Avec du style&lt;/li&gt;
&lt;li&gt;Du texte haut en couleur&lt;/li&gt;
&lt;li&gt;Le Système de coordonnées&lt;/li&gt;
&lt;li&gt;La Conversion des coordonnées logiques en coordonnées physiques (et inversement)&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;/ul&gt;</description>
    
          <enclosure url="http://doc.qtfr.org/public/2007/dessiner-avec-qt4.pdf"
      length="342258" type="application/pdf" />
    
    
      </item>
    
  <item>
    <title>Ouverture d'une boîte de dialogue à partir de la fenêtre principale</title>
    <link>http://doc.qtfr.org/post/2007/04/10/Ouverture-dune-fenetre-a-partir-de-la-fenetre-principale</link>
    <guid isPermaLink="false">urn:md5:a00ab0041f9ff6004a286a94edc362e4</guid>
    <pubDate>Sun, 15 Apr 2007 18:24:00 +0200</pubDate>
    <dc:creator>IrmatDen</dc:creator>
        <category>Tutoriels</category>
        <category>class_QAction</category><category>class_QDialog</category><category>class_QMenu</category><category>class_QMessageBox</category><category>signaux-slots</category><category>version_Qt4</category>    
    <description>&lt;p&gt;Ce tutoriel est destiné aux nouveaux venus à Qt qui cherche à savoir comment ouvrir une fenêtre à partir de leur fenêtre principale. Nous verrons 2 façons de faire:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;utilisation d'une fenêtre principale avec menus pour ouvrir une boîte de dialogue et une boite &quot;A propos...&quot;&lt;/li&gt;
&lt;li&gt;ouverture d'une fenêtre de dialogue par le biais d'un bouton&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;J'en profiterais pour aborder très brièvement 2 autres points&amp;nbsp;: l'utilisation de &lt;code&gt;QAction&lt;/code&gt; et les 2 modes d'affichage des boîtes de dialogue.&lt;/p&gt;


&lt;p&gt;&lt;strong&gt;Version&lt;/strong&gt;&amp;nbsp;: Qt4 (et une version pyQt disponible)&lt;br /&gt;
&lt;strong&gt;Auteur&lt;/strong&gt;&amp;nbsp;: Denys Bulant (&lt;a href=&quot;http://forum.qtfr.org/profile.php?id=291&quot;&gt;IrmatDen&lt;/a&gt;), &lt;a href=&quot;http://doc.qtfr.org/post/2007/04/10/[http://forum.qtfr.org/profile.php?id=2344&quot;&gt;alteo_gange&lt;/a&gt; pour la version pyQt&lt;br /&gt;
&lt;strong&gt;Fil de discussion&lt;/strong&gt;&amp;nbsp;: &lt;a href=&quot;http://forum.qtfr.org/viewtopic.php?pid=31512&quot;&gt;Forum&lt;/a&gt;&lt;/p&gt;    &lt;h2&gt;Pré requis:&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;une installation de Qt4 fonctionnelle&lt;/li&gt;
&lt;li&gt;une connaissance minimale du principe des signaux/slots avec Qt&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;Une introduction aux boîtes de dialogue&lt;/h2&gt;


&lt;p&gt;Les boîtes de dialogue sont des composants essentiel à la très grosse majorité des applications. Qu'il s'agisse de boîte de configuration ou de fournir une interactivité à un niveau plus ou moins bas avec le document ouvert (par exemple, la recherche dans un traitement de texte ou un tableur), vous aurez souvent l'occasion d'en utiliser.&lt;/p&gt;


&lt;p&gt;On distingue 2 types d'utilisation des boîtes de dialogue:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;non modale: l'utilisateur peut continuer d'interagir avec le reste de l'application&lt;/li&gt;
&lt;li&gt;modale: l'utilisateur est obligé de fermer la boîte de dialogue affichée avant de pouvoir à nouveau se servir de l'application&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Chaque usage à son but; par exemple, une boîte de dialogue permettant une recherche dans un document aura tout intérêt à être non modale par souci d'ergonomie. Par contre, une fenêtre de configuration devrait plutôt être modale, dûe à une éventuelle dépendance du résultat sur le comportement de l'application.&lt;/p&gt;


&lt;h2&gt;A propos de ce tuto&lt;/h2&gt;


&lt;p&gt;Ce tuto vous permettra, je l'espère de vous familiariser avec &lt;code&gt;QDialog&lt;/code&gt; principalement, et plus globalement l'ouverture de fenêtre à partir d'une autre. Je fourni ici 2 approches:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;la première est l'ouverture d'une fenêtre en appuyant sur un bouton: elle est la méthode la plus simple, mais pas forcèment la plus commune&lt;/li&gt;
&lt;li&gt;la seconde fait utilisation d'un menu, et vous montre comment afficher une boîte de type &quot;A propos...&quot;. Il y est fait appel à 2 concepts supplémentaires: les menus et les actions. Le code est loin d'être compliqué, mais assurez-vous d'avoir compris la première partie pour lire la seconde.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Comme dit dans l'introduction, une version pyQt a été réalisée par &lt;a href=&quot;http://doc.qtfr.org/post/2007/04/10/[http://forum.qtfr.org/profile.php?id=2344&quot;&gt;alteo_gange&lt;/a&gt;. Elle est disponible sur le &lt;a href=&quot;http://forum.qtfr.org/viewtopic.php?pid=32334#p32334&quot;&gt;forum&lt;/a&gt;.&lt;/p&gt;


&lt;h2&gt;Partie 0: Lectrice/Lecteur, voici &lt;a href=&quot;http://doc.trolltech.com/4.2/qdialog.html&quot; hreflang=&quot;en&quot;&gt;QDialog&lt;/a&gt;; QDialog, voici ton futur maître ;-)&lt;/h2&gt;


&lt;p&gt;Avant de sauter dans le vif du sujet, faisons plus ample connaissance avec la classe &lt;code&gt;QDialog&lt;/code&gt;. Vous vous en doutez probablement, elle réalise ce qu'une boîte de dialogue est sensée faire, et permet quelques raccourcis que vous n'auriez pas si vous dériviez d'un &lt;code&gt;QWidget&lt;/code&gt;.&lt;/p&gt;


&lt;p&gt;Cette section sert de très brève introduction aux fonctions les plus basiques de &lt;code&gt;QDialog&lt;/code&gt;. Je vous invite à aller lire la &lt;a href=&quot;http://doc.trolltech.com/4.2/qdialog.html#details&quot; hreflang=&quot;en&quot;&gt;description&lt;/a&gt; détaillée sur la page de documentation de Trolltech. Ils en parlent bien mieux que moi.&lt;/p&gt;


&lt;h3&gt;De la modalité et différences entre les fonctions d'affichage&lt;/h3&gt;


&lt;p&gt;Afficher une instance de &lt;code&gt;QDialog&lt;/code&gt; peut se faire de plusieurs façons. En voici un aperçu:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;QDialog::show()&lt;/code&gt;: QDialog::show(): utilisé pour un affichage de la boîte de dialogue; par défaut l'affichage est non modal; peut servir à afficher un &lt;code&gt;QDialog&lt;/code&gt; de façon modale si &lt;code&gt;setModal(true)&lt;/code&gt; à été appellé précédemment.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;QDialog::hide()&lt;/code&gt;: permet de cacher une boite de dialogue&lt;/li&gt;
&lt;li&gt;&lt;code&gt;QWidget::setVisible()&lt;/code&gt; et &lt;code&gt;QWidget::isVisible()&lt;/code&gt;: &lt;code&gt;QDialog&lt;/code&gt; dérive de &lt;code&gt;QWidget&lt;/code&gt;, et fournit donc cette alternative à &lt;code&gt;show()/hide()&lt;/code&gt;. L'utilité de ces fonctions se trouve principalement dans la possibilité de changer la visibilité d'une fenêtre en une ligne de code.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;QDialog::exec()&lt;/code&gt;: sert à afficher une boite de dialogue modale et éventuellement récupérer le code de retour&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;Valeurs de retours&lt;/h3&gt;


&lt;p&gt;Il peut être parfois utile de savoir si l'interaction demandée à l'utilisateur par le biais de votre boîte de dialogue à réussi ou échoué (dans le cas d'une boîte modale).
&lt;code&gt;QDialog::exec()&lt;/code&gt; renvoit un code d'erreur qui est soit &lt;code&gt;QDialog::Accepted&lt;/code&gt;, soit &lt;code&gt;QDialog::Rejected&lt;/code&gt; (ou encore une de vos valeurs propres dans des cas peu courants). La première valeur signifie un succès, tandis que la seconde indique soit un échec, soit un refus ou une annulation.
Du côté de votre boîte de dialogue, vous pouvez renvoyer ces valeurs de diverses façons:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;QDialog::accept()&lt;/code&gt;: &lt;code&gt;QDialog::Accepted&lt;/code&gt; sera la valeur renvoyée par &lt;code&gt;exec()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;QDialog::reject()&lt;/code&gt;: &lt;code&gt;QDialog::Rejected&lt;/code&gt; sera renvoyée&lt;/li&gt;
&lt;li&gt;&lt;code&gt;QDialog::done(int)&lt;/code&gt;: vous permet de spécifier l'une des 2 valeurs, mais aussi de spécifier la votre si vous en avez un réél besoin (utilisation assez rare tout de même).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;Une boîte de dialogue...&lt;/h3&gt;


&lt;p&gt;La classe définie ici sera celle que nous allons afficher dans les 2 exemples suivant. Elle n'est composée que d'un bouton &quot;Fermer&quot;.&lt;/p&gt;
&lt;pre class=&quot;cpp&quot;&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;class&lt;/span&gt; Dialog : &lt;span style=&quot;color: #0000ff;&quot;&gt;public&lt;/span&gt; QDialog
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
&lt;span style=&quot;color: #0000ff;&quot;&gt;public&lt;/span&gt;:
	Dialog&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;QWidget *parent=&lt;span style=&quot;color: #0000dd;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
	:QDialog&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;parent&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
	&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
		&lt;span style=&quot;color: #ff0000;&quot;&gt;// Elle est simplement composé d'un bouton &amp;quot;Fermer&amp;quot;&lt;/span&gt;
		QPushButton *closeBtn = &lt;span style=&quot;color: #0000dd;&quot;&gt;new&lt;/span&gt; QPushButton&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot;Fermer&amp;quot;&lt;/span&gt;, &lt;span style=&quot;color: #0000dd;&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
&amp;nbsp;
		&lt;span style=&quot;color: #ff0000;&quot;&gt;// lequel ferme la fenetre lorsqu'on clic dessus&lt;/span&gt;
		connect&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;closeBtn, &lt;span style=&quot;color: #0000ff;&quot;&gt;SIGNAL&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;clicked&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;, &lt;span style=&quot;color: #0000dd;&quot;&gt;this&lt;/span&gt;, SLOT&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;accept&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
	&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;;&lt;/pre&gt;


&lt;h2&gt;Partie 1: ouverture de fenêtre avec des boutons&lt;/h2&gt;

&lt;h3&gt;Classes abordées:&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://doc.trolltech.com/4.2/qdialog.html&quot; hreflang=&quot;en&quot;&gt;QDialog&lt;/a&gt;: sert de classe de base aux boîtes de dialogue&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://doc.trolltech.com/4.2/qpushbutton.html&quot; hreflang=&quot;en&quot;&gt;QPushButton&lt;/a&gt;: déclenche l'affichage des boites de dialogue, et quitte l'application&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;Description de la solution&lt;/h3&gt;


&lt;p&gt;Bien que rarement utilisée/utilisable à cause du &quot;clicodrome&quot; qui risque d'être engendré (affichage d'une boîte de dialogue qui en appelle une autre qui... :)), cette méthode permet d'illustrer simplement l'ouverture d'une boîte de dialogue. Ceci dit, il peut toujours y avoir besoin d'une telle utilisation, ne serait-ce que parce que votre widget principal ne possède pas de menu.&lt;/p&gt;


&lt;h3&gt;Exemple&lt;/h3&gt;


&lt;p&gt;Voici la classe principale. C'est à partir de celle-ci que nous allons demander l'ouverture d'une instance de &lt;code&gt;Dialog&lt;/code&gt;&lt;/p&gt;
&lt;pre class=&quot;cpp&quot;&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;class&lt;/span&gt; MainDialog : &lt;span style=&quot;color: #0000ff;&quot;&gt;public&lt;/span&gt; QDialog
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
	Q_OBJECT
&amp;nbsp;
&lt;span style=&quot;color: #0000ff;&quot;&gt;public&lt;/span&gt;:
	MainDialog&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;QWidget *parent=&lt;span style=&quot;color: #0000dd;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
	:QDialog&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;parent&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;, dlg&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000dd;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
	&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
		dlg = &lt;span style=&quot;color: #0000dd;&quot;&gt;new&lt;/span&gt; Dialog&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000dd;&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
&amp;nbsp;
		&lt;span style=&quot;color: #ff0000;&quot;&gt;// Ce bouton nous permettra d'afficher notre boîte de dialogue&lt;/span&gt;
		QPushButton *modalDlgBtn = &lt;span style=&quot;color: #0000dd;&quot;&gt;new&lt;/span&gt; QPushButton&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot; Open Modal dialog&amp;quot;&lt;/span&gt;, &lt;span style=&quot;color: #0000dd;&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
&amp;nbsp;
		&lt;span style=&quot;color: #ff0000;&quot;&gt;// J'agrandis la fenetre pour que dlg soit visuellement différenciable de celle-ci&lt;/span&gt;
		resize&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000dd;&quot;&gt;250&lt;/span&gt;,&lt;span style=&quot;color: #0000dd;&quot;&gt;50&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
&amp;nbsp;
		&lt;span style=&quot;color: #ff0000;&quot;&gt;// On demande à Qt d'executer showDialogModal() lorsque le bouton est clique&lt;/span&gt;
		connect&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;modalDlgBtn, &lt;span style=&quot;color: #0000ff;&quot;&gt;SIGNAL&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;clicked&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;, &lt;span style=&quot;color: #0000dd;&quot;&gt;this&lt;/span&gt;, SLOT&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;showDialogModal&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
	&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
&lt;span style=&quot;color: #0000ff;&quot;&gt;private&lt;/span&gt; slots:
	&lt;span style=&quot;color: #0000ff;&quot;&gt;void&lt;/span&gt; showDialogModal&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
	&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
		&lt;span style=&quot;color: #ff0000;&quot;&gt;// on affiche la boite de dialogue de facon modale&lt;/span&gt;
		dlg-&amp;gt;setModal&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;true&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
		dlg-&amp;gt;show&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
	&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
&lt;span style=&quot;color: #0000ff;&quot;&gt;private&lt;/span&gt;:
	Dialog *dlg;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;;&lt;/pre&gt;


&lt;h2&gt;Partie 2: utilisation d'une fenêtre principale avec menus pour ouvrir une boîte de dialogue et une boite &quot;A propos...&quot;&lt;/h2&gt;

&lt;h3&gt;Classes abordées:&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://doc.trolltech.com/4.2/qmainwindow.html&quot; hreflang=&quot;en&quot;&gt;QMainWindow&lt;/a&gt;: nous en dériverons pour créer une fenêtre principale avec barre de menu&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://doc.trolltech.com/4.2/qdialog.html&quot; hreflang=&quot;en&quot;&gt;QDialog&lt;/a&gt;: sert de classe de base à notre boîte de dialogue&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://doc.trolltech.com/4.2/qmessagebox.html&quot; hreflang=&quot;en&quot;&gt;QMessageBox&lt;/a&gt;: affichage d'un message &quot;A propos...&quot;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://doc.trolltech.com/4.2/qaction.html&quot; hreflang=&quot;en&quot;&gt;QAction&lt;/a&gt;: permet de centraliser et coordonner le comportement et l'apparence entre des choix de menus ou des boutons sur une barre d'outils (chose que nous ne verrons pas ici)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;Description de la solution&lt;/h3&gt;


&lt;p&gt;Nous allons utiliser ici un menu pour permettre d'ouvrir une boîte de dialogue de façon modale, non modale, et enfin une descrption de ce petit code. La classe &lt;code&gt;QAction&lt;/code&gt; permet d'ajouter des fonctionnalités à un menu, ainsi qu'à d'éventuelles barre d'outils.&lt;/p&gt;


&lt;h3&gt;Exemple&lt;/h3&gt;


&lt;p&gt;C'est à partir de l'interface décrite ci-dessous que nous allons demander l'ouverture d'une instance de &lt;code&gt;Dialog&lt;/code&gt;, que ce soit de façon modale ou non.&lt;/p&gt;
&lt;pre class=&quot;cpp&quot;&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;class&lt;/span&gt; MainWindow : &lt;span style=&quot;color: #0000ff;&quot;&gt;public&lt;/span&gt; QMainWindow
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
Q_OBJECT
&amp;nbsp;
&lt;span style=&quot;color: #0000ff;&quot;&gt;public&lt;/span&gt;:
	MainWindow&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;QWidget *parent=&lt;span style=&quot;color: #0000dd;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
	:QMainWindow&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;parent&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;, dlg&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000dd;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
	&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
		&lt;span style=&quot;color: #ff0000;&quot;&gt;// Nous creons l'instance de dialogue que nous voulons afficher&lt;/span&gt;
		dlg = &lt;span style=&quot;color: #0000dd;&quot;&gt;new&lt;/span&gt; Dialog&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000dd;&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
&amp;nbsp;
		&lt;span style=&quot;color: #ff0000;&quot;&gt;// Les actions correspondront aux items de menus&lt;/span&gt;
		QAction *modelessAct = &lt;span style=&quot;color: #0000dd;&quot;&gt;new&lt;/span&gt; QAction&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot;Dialogue non modale&amp;quot;&lt;/span&gt;, &lt;span style=&quot;color: #0000dd;&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
		QAction *modalAct = &lt;span style=&quot;color: #0000dd;&quot;&gt;new&lt;/span&gt; QAction&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot;Afficher dialogue modale&amp;quot;&lt;/span&gt;, &lt;span style=&quot;color: #0000dd;&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
		QAction *aboutAct = &lt;span style=&quot;color: #0000dd;&quot;&gt;new&lt;/span&gt; QAction&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot;A propos...&amp;quot;&lt;/span&gt;, &lt;span style=&quot;color: #0000dd;&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
		QAction *closeAct = &lt;span style=&quot;color: #0000dd;&quot;&gt;new&lt;/span&gt; QAction&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot;Quitter&amp;quot;&lt;/span&gt;, &lt;span style=&quot;color: #0000dd;&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
&amp;nbsp;
		&lt;span style=&quot;color: #ff0000;&quot;&gt;// Nous créons le menu proprement dit. Nous y ajoutons les actions précédemment crées&lt;/span&gt;
		QMenu *menu = menuBar&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;-&amp;gt;addMenu&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot;Divers...&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
		menu-&amp;gt;addAction&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;modelessAct&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
		menu-&amp;gt;addAction&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;modalAct&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
		menu-&amp;gt;addAction&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;aboutAct&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
		menu-&amp;gt;addAction&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;closeAct&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
&amp;nbsp;
		&lt;span style=&quot;color: #ff0000;&quot;&gt;// Définition des comportements des actions&lt;/span&gt;
		connect&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;modelessAct, &lt;span style=&quot;color: #0000ff;&quot;&gt;SIGNAL&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;triggered&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;, &lt;span style=&quot;color: #0000dd;&quot;&gt;this&lt;/span&gt;, SLOT&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;swapShowDialogModeless&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
		connect&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;modalAct, &lt;span style=&quot;color: #0000ff;&quot;&gt;SIGNAL&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;triggered&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;, &lt;span style=&quot;color: #0000dd;&quot;&gt;this&lt;/span&gt;, SLOT&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;showDialogModal&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
		connect&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;aboutAct, &lt;span style=&quot;color: #0000ff;&quot;&gt;SIGNAL&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;triggered&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;, &lt;span style=&quot;color: #0000dd;&quot;&gt;this&lt;/span&gt;, SLOT&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;about&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
		connect&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;closeAct, &lt;span style=&quot;color: #0000ff;&quot;&gt;SIGNAL&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;triggered&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;, qApp, SLOT&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;quit&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
	&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
&lt;span style=&quot;color: #0000ff;&quot;&gt;private&lt;/span&gt; slots:
	&lt;span style=&quot;color: #ff0000;&quot;&gt;// Affichée de façon modeless, l'utilisateur peut continuer d'interagir avec le reste de l'application&lt;/span&gt;
	&lt;span style=&quot;color: #0000ff;&quot;&gt;void&lt;/span&gt; swapShowDialogModeless&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
	&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
		&lt;span style=&quot;color: #ff0000;&quot;&gt;// Si elle est deja affichee, on cache la boite de dialogue sinon on l'affiche&lt;/span&gt;
		dlg-&amp;gt;setVisible&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;!dlg-&amp;gt;isVisible&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
	&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
	&lt;span style=&quot;color: #ff0000;&quot;&gt;// En version modale, une boite de dialogue empêche l'utilisateur d'intervenir sur une autre partie&lt;/span&gt;
	&lt;span style=&quot;color: #ff0000;&quot;&gt;// de l'interface que la boite de dialogue&lt;/span&gt;
	&lt;span style=&quot;color: #0000ff;&quot;&gt;void&lt;/span&gt; showDialogModal&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
	&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
		&lt;span style=&quot;color: #ff0000;&quot;&gt;// On s'assure que notre boite de dialogue n'est pas déjà affichée de façon non modale&lt;/span&gt;
		&lt;span style=&quot;color: #0000ff;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;dlg-&amp;gt;isVisible&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
		&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
			QMessageBox::&lt;span style=&quot;color: #00eeff;&quot;&gt;critical&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000dd;&quot;&gt;this&lt;/span&gt;, &lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot;Erreur&amp;quot;&lt;/span&gt;, &lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot;La boite de dialogue est déjà ouverte. Veuillez la fermer pour l'ouvrir à nouveau.&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
		&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
		&lt;span style=&quot;color: #0000ff;&quot;&gt;else&lt;/span&gt;
		&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
			dlg-&amp;gt;exec&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
		&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
	&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
	&lt;span style=&quot;color: #ff0000;&quot;&gt;// Affichage d'information à propos de ce &amp;quot;logiciel&amp;quot;&lt;/span&gt;
	&lt;span style=&quot;color: #0000ff;&quot;&gt;void&lt;/span&gt; about&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
	&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
		QMessageBox::&lt;span style=&quot;color: #00eeff;&quot;&gt;about&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000dd;&quot;&gt;this&lt;/span&gt;, &lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot;Tuto: Menus et dialogues&amp;quot;&lt;/span&gt;,
			&lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot;Cette application est destinée à illustrer:&lt;span style=&quot;color: #666666; font-weight: bold;&quot;&gt;\n&lt;/span&gt;&amp;quot;&lt;/span&gt; \
			&lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot;&amp;gt; l'ouverture de boîte de dialogue&lt;span style=&quot;color: #666666; font-weight: bold;&quot;&gt;\n&lt;/span&gt;&amp;quot;&lt;/span&gt; \
			&lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot;&amp;gt; l'ouverture d'une fenetre &lt;span style=&quot;color: #666666; font-weight: bold;&quot;&gt;\&amp;quot;&lt;/span&gt;A propos...&lt;span style=&quot;color: #666666; font-weight: bold;&quot;&gt;\&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #666666; font-weight: bold;&quot;&gt;\n&lt;/span&gt;&amp;quot;&lt;/span&gt; \
			&lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot;&amp;gt; et une rapide introduction à QAction&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
	&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
&lt;span style=&quot;color: #0000ff;&quot;&gt;private&lt;/span&gt;:
	Dialog *dlg;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;;&lt;/pre&gt;


&lt;h2&gt;Archive&lt;/h2&gt;


&lt;p&gt;Vous trouverez attaché à cette article une archive composée de 2 sous répertoires:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;bouton: exemple de la première partie&lt;/li&gt;
&lt;li&gt;menu: exemple de la seconde&lt;/li&gt;
&lt;/ul&gt;</description>
    
          <enclosure url="http://doc.qtfr.org/public/2007/dialog_from_window.zip"
      length="3117" type="application/zip" />
    
    
      </item>
    
  <item>
    <title>Utilisation du designer avec Qt4</title>
    <link>http://doc.qtfr.org/post/2007/04/01/Utilisation-du-designer</link>
    <guid isPermaLink="false">urn:md5:aa23d5c8b879d74148beac07811eecf6</guid>
    <pubDate>Wed, 04 Apr 2007 21:33:00 +0200</pubDate>
    <dc:creator>Nicolas</dc:creator>
        <category>Documentation</category>
        <category>designer</category><category>signaux-slots</category><category>version_Qt4</category>    
    <description>&lt;ul&gt;
&lt;li&gt;Comment intégrer un widget créé avec le designer&amp;nbsp;?&lt;/li&gt;
&lt;li&gt;Comment utiliser les fichiers .ui créés par le designer&amp;nbsp;?&lt;/li&gt;
&lt;li&gt;Quelle est la différence entre les trois méthodes d'intégration?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Cet article va détailler l'utilisation du designer et l'intégration d'un widget créé avec le designer dans notre programme. Cet article est une &lt;em&gt;adaptation libre&lt;/em&gt; de la documentation de Qt&amp;nbsp;: &lt;a href=&quot;http://doc.trolltech.com/4.2/designer-using-a-component.html&quot; hreflang=&quot;en&quot;&gt;Using a Component in Your Application&lt;/a&gt;.&lt;/p&gt;


&lt;p&gt;&lt;strong&gt;Version&lt;/strong&gt;&amp;nbsp;: Qt4 (supérieur ou égal à Qt 4.1) &lt;br /&gt;
&lt;strong&gt;Auteur&lt;/strong&gt;&amp;nbsp;: Nicolas Arnaud-Cormos (&lt;a href=&quot;http://forum.qtfr.org/profile.php?id=7&quot;&gt;nikikko&lt;/a&gt;)&lt;br /&gt;
&lt;strong&gt;Test&lt;/strong&gt;&amp;nbsp;: Linux (Qt 4.2)&lt;/p&gt;    &lt;h3&gt;Introduction&lt;/h3&gt;


&lt;p&gt;Depuis Qt4, le designer a repris sa fonction première&amp;nbsp;: la création &lt;acronym title=&quot;What You See Is What You Get&quot;&gt;WYSIWYG&lt;/acronym&gt; de &lt;em&gt;forms&lt;/em&gt;(terme générique pour désigner soit une fenêtre principale, soit une boîte de dialogue, soit un widget personnalisé). L'utilisation du designer en lui-même et les différences entre ces &lt;em&gt;forms&lt;/em&gt; ne seront pas abordés ici.&lt;/p&gt;


&lt;p&gt;Une fois que l'utilisateur a créé une &lt;em&gt;form&lt;/em&gt; et l'enregistre sur le disque, il crée un fichier &lt;code&gt;.ui&lt;/code&gt; qui n'est autre qu'un fichier XML décrivant la &lt;em&gt;form&lt;/em&gt;&amp;nbsp;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;widgets qui composent la &lt;em&gt;form&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;organisation (layout) et position des différents widgets&lt;/li&gt;
&lt;li&gt;connexions entre les différents widgets&lt;/li&gt;
&lt;li&gt;...&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Ce fichier &lt;code&gt;.ui&lt;/code&gt; n'est pas directement compilable&amp;nbsp;: pour être utilisé, il doit être converti en fichier C++ à l'aide de l'outil &lt;code&gt;uic&lt;/code&gt;. Avec l'utilisation combinée de &lt;code&gt;uic&lt;/code&gt; et de &lt;code&gt;qmake&lt;/code&gt;, le code C++ est généré automatiquement lors de la compilation de l'application.&lt;/p&gt;


&lt;p&gt;Il existe trois méthodes différentes pour intégrer les &lt;em&gt;forms&lt;/em&gt; créées avec le designer. Pour l'exemple, vous pouvez utiliser n'importe quelle &lt;em&gt;form&lt;/em&gt;, vous en trouverez une en annexe de cet article (qui s'appelle &lt;code&gt;mywidget.ui&lt;/code&gt;)&amp;nbsp;:&lt;/p&gt;


&lt;p&gt;&lt;img src=&quot;http://doc.qtfr.org/public/2007/designer-exemple.png&quot; alt=&quot;designer-exemple.png&quot; style=&quot;display:block; margin:0 auto;&quot; /&gt;&lt;/p&gt;


&lt;h4&gt;Fichier généré&lt;/h4&gt;

&lt;p&gt;Le fichier généré par &lt;code&gt;uic&lt;/code&gt; n'est pas un &lt;code&gt;QWidget&lt;/code&gt; (ou &lt;code&gt;QMainApplication&lt;/code&gt;/&lt;code&gt;QDialog&lt;/code&gt;), mais c'est juste une classe de description de l'interface contenant le code de création et d'organisation des widgets, ainsi que les connexions définies dans le designer.&lt;/p&gt;


&lt;p&gt;Par exemple, à partir du fichier &lt;code&gt;mywidget.ui&lt;/code&gt;&amp;nbsp;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;un fichier &lt;code&gt;ui_mywidget.h&lt;/code&gt; va être créé,&lt;/li&gt;
&lt;li&gt;ce fichier contient une classe dans le namespace &lt;strong&gt;Ui&lt;/strong&gt;&amp;nbsp;: &lt;code&gt;Ui::MyWidget&lt;/code&gt; (pour rappel, MyWidget est le nom que j'ai donné à la &lt;em&gt;form&lt;/em&gt; dans le designer),&lt;/li&gt;
&lt;li&gt;cette classe contient une fonction importante&amp;nbsp;: &lt;code&gt;void setupUi(QWidget *MyWidget)&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;


&lt;h3&gt;&lt;a name=&quot;direct&quot;&gt;&lt;/a&gt; Méthode directe&lt;/h3&gt;


&lt;p&gt;La méthode directe est relativement simple&amp;nbsp;: un widget va être créé pour servir de conteneur à notre &lt;em&gt;form&lt;/em&gt;. Voici le .pro utilisé.&lt;/p&gt;
&lt;pre&gt;
TEMPLATE    = app
FORMS       = mywidget.ui
SOURCES     = main.cpp
&lt;/pre&gt;


&lt;blockquote&gt;&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;&amp;nbsp;: il ne faut pas indiquer le fichier créé par &lt;code&gt;uic&lt;/code&gt;, ici &lt;code&gt;ui_mywidget.h&lt;/code&gt;, ce dernier étant implicitement déclaré par le &lt;code&gt;FORMS&lt;/code&gt;&lt;/p&gt;&lt;/blockquote&gt;


&lt;p&gt;La fonction &lt;code&gt;main&lt;/code&gt; va créer un widget qui servira de conteneur à l'interface&amp;nbsp;: c'est la ligne &lt;code&gt;ui.setupUi(window);&lt;/code&gt;. Voici le fichier complet&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;cpp&quot;&gt;&lt;span style=&quot;color: #339900;&quot;&gt;#include &amp;lt;QApplication&amp;gt;&lt;/span&gt;
&lt;span style=&quot;color: #339900;&quot;&gt;#include &amp;quot;ui_mywidget.h&amp;quot;&lt;/span&gt;
&amp;nbsp;
&lt;span style=&quot;color: #0000ff;&quot;&gt;int&lt;/span&gt; main&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;int&lt;/span&gt; argc, &lt;span style=&quot;color: #0000ff;&quot;&gt;char&lt;/span&gt; *argv&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
    QApplication app&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;argc, argv&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
    QWidget *window = &lt;span style=&quot;color: #0000dd;&quot;&gt;new&lt;/span&gt; QWidget;
    Ui::&lt;span style=&quot;color: #00eeff;&quot;&gt;MyWidget&lt;/span&gt; ui;
    ui.&lt;span style=&quot;color: #00eeff;&quot;&gt;setupUi&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;window&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
&amp;nbsp;
    window-&amp;gt;show&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
    &lt;span style=&quot;color: #0000ff;&quot;&gt;return&lt;/span&gt; app.&lt;span style=&quot;color: #00eeff;&quot;&gt;exec&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Bien que rapide et simple d'utilisation, &lt;strong&gt;cette méthode est très limitée&lt;/strong&gt; car elle ne permet pas de définir des signaux et slots, de connecter des éléments entre eux... cette méthode est utile pour des fenêtres statiques, comme par exemple des fenêtres &lt;q&gt;A propos&lt;/q&gt;.&lt;/p&gt;



&lt;h3&gt;&lt;a name=&quot;simple&quot;&gt;&lt;/a&gt; Méthode héritage simple&lt;/h3&gt;


&lt;p&gt;Ici, plutôt que de créer un widget puis de lui appliquer une interface à l'aide de la fonction &lt;code&gt;setupUi&lt;/code&gt;, nous allons créer une classe qui hérite de &lt;code&gt;QWidget&lt;/code&gt; (ou &lt;code&gt;QDialog&lt;/code&gt;/&lt;code&gt;QMainWindow&lt;/code&gt;, en fonction du type de &lt;em&gt;form&lt;/em&gt; créée) et lui appliquer l'interface dans le constructeur&amp;nbsp;: une instance de la classe &lt;code&gt;Ui::MyWidget&lt;/code&gt; est déclarée comme membre de notre classe.&lt;/p&gt;

&lt;pre class=&quot;cpp&quot;&gt;&lt;span style=&quot;color: #339900;&quot;&gt;#include &amp;quot;ui_mywidget.h&amp;quot;&lt;/span&gt;
&lt;span style=&quot;color: #339900;&quot;&gt;#include &amp;lt;QWidget&amp;gt;&lt;/span&gt;
&amp;nbsp;
&lt;span style=&quot;color: #0000ff;&quot;&gt;class&lt;/span&gt; MyWidget : &lt;span style=&quot;color: #0000ff;&quot;&gt;public&lt;/span&gt; QWidget
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
    Q_OBJECT
&amp;nbsp;
&lt;span style=&quot;color: #0000ff;&quot;&gt;public&lt;/span&gt;:
    MyWidget&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;QWidget *parent = &lt;span style=&quot;color: #0000dd;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
...
&lt;span style=&quot;color: #0000ff;&quot;&gt;private&lt;/span&gt;:
    Ui::&lt;span style=&quot;color: #00eeff;&quot;&gt;MyWidget&lt;/span&gt; ui;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;;&lt;/pre&gt;


&lt;p&gt;Il est toujours nécessaire d'appeler la fonction &lt;code&gt;setupUi&lt;/code&gt;, mais cette fois-ci dans le constructeur de notre classe &lt;code&gt;MyWidget&lt;/code&gt;&amp;nbsp;:&lt;/p&gt;
&lt;pre class=&quot;cpp&quot;&gt;MyWidget::&lt;span style=&quot;color: #00eeff;&quot;&gt;MyWidget&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;QWidget *parent&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
    : QWidget&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;parent&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
    ui.&lt;span style=&quot;color: #00eeff;&quot;&gt;setupUi&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000dd;&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;L'avantage ici, c'est que la déclaration de l'interface est un membre de la classe, les différents widgets ainsi que les layouts/signaux/méthodes sont donc directement accessible dans notre classe &lt;code&gt;MyWidget&lt;/code&gt;. Nous allons par exemple ajouter un slot &lt;code&gt;clickMe()&lt;/code&gt; qui sera connecté sur un clic sur le bouton &lt;q&gt;Cliquez moi !!&lt;/q&gt; (qui porte bien son nom)&amp;nbsp;:&lt;/p&gt;
&lt;pre class=&quot;cpp&quot;&gt;MyWidget::&lt;span style=&quot;color: #00eeff;&quot;&gt;MyWidget&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;QWidget *parent&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
    : QWidget&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;parent&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
    ui.&lt;span style=&quot;color: #00eeff;&quot;&gt;setupUi&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000dd;&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
    connect&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;ui.&lt;span style=&quot;color: #00eeff;&quot;&gt;pushButton&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;SIGNAL&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;clicked&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;, &lt;span style=&quot;color: #0000dd;&quot;&gt;this&lt;/span&gt;, SLOT&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;clickMe&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
&lt;span style=&quot;color: #0000ff;&quot;&gt;void&lt;/span&gt; MyWidget::&lt;span style=&quot;color: #00eeff;&quot;&gt;clickMe&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
    ui.&lt;span style=&quot;color: #00eeff;&quot;&gt;lineEdit&lt;/span&gt;-&amp;gt;setText&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot;YEAH !!!&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;blockquote&gt;&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;&amp;nbsp;: remarquez ici que tous les widgets qui composent la &lt;em&gt;form&lt;/em&gt; sont appelés à l'aide du membre &lt;strong&gt;ui&lt;/strong&gt;.&lt;/p&gt;&lt;/blockquote&gt;


&lt;p&gt;Cette méthode offre de &lt;strong&gt;nombreux avantages&lt;/strong&gt; au développeur&amp;nbsp;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;accès aux différents widgets de la &lt;em&gt;form&lt;/em&gt;,&lt;/li&gt;
&lt;li&gt;encapsulation de l'interface dans un widget facilement utilisable,&lt;/li&gt;
&lt;li&gt;possibilité d'utiliser plusieurs interfaces...&lt;/li&gt;
&lt;/ul&gt;


&lt;h4&gt;A propos des noms&lt;/h4&gt;

&lt;p&gt;Comme vous l'avez remarqué, j'ai employé le même nom partout&amp;nbsp;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;3 fichiers&amp;nbsp;: &lt;code&gt;mywidget.ui&lt;/code&gt;, &lt;code&gt;mywidget.h&lt;/code&gt; et &lt;code&gt;mywidget.cpp&lt;/code&gt;,&lt;/li&gt;
&lt;li&gt;dans le designer, l'interface s'appelle &lt;code&gt;MyWidget&lt;/code&gt; et lors de la compilation, la classe &lt;code&gt;Ui::MyWidget&lt;/code&gt; est créée,&lt;/li&gt;
&lt;li&gt;la classe dérivée s'appelle aussi &lt;code&gt;MyWidget&lt;/code&gt; (pas de problème de nommage, la classe précédente étant dans un namespace).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;C'est une préférence personnelle, mais &lt;em&gt;il est tout à fait possible d'utiliser des noms différents entre l'interface  et la classe dérivée&lt;/em&gt;. On peut par exemple imaginer deux classes différentes qui partagent la même interface.&lt;/p&gt;



&lt;h4&gt;Compilation&lt;/h4&gt;

&lt;p&gt;Il est nécessaire de modifier notre fichier .pro utilisé pour la compilation, en ajoutant la classe créée&amp;nbsp;:&lt;/p&gt;
&lt;pre&gt;
TEMPLATE    = app
FORMS       = mywidget.ui
SOURCES     = main.cpp \
              mywidget.cpp
HEADERS     = mywidget.h
&lt;/pre&gt;


&lt;blockquote&gt;&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;&amp;nbsp;: il ne faut pas indiquer le fichier créé par &lt;code&gt;uic&lt;/code&gt;, ici &lt;code&gt;ui_mywidget.h&lt;/code&gt;, ce dernier étant implicitement déclaré par le &lt;code&gt;FORMS&lt;/code&gt;&lt;/p&gt;&lt;/blockquote&gt;



&lt;h3&gt;&lt;a name=&quot;multiple&quot;&gt;&lt;/a&gt; Méthode héritage multiple&lt;/h3&gt;


&lt;p&gt;Cette méthode est très proche de la méthode précédente (les notes sur le choix des noms et sur la compilation sont toujours valables), la différence étant que l'interface n'est plus un membre de la classe héritée, mais elle est aussi héritée par le widget&amp;nbsp;:&lt;/p&gt;
&lt;pre class=&quot;cpp&quot;&gt;&lt;span style=&quot;color: #339900;&quot;&gt;#include &amp;quot;ui_mywidget.h&amp;quot;&lt;/span&gt;
&lt;span style=&quot;color: #339900;&quot;&gt;#include &amp;lt;QWidget&amp;gt;&lt;/span&gt;
&amp;nbsp;
&lt;span style=&quot;color: #0000ff;&quot;&gt;class&lt;/span&gt; MyWidget : &lt;span style=&quot;color: #0000ff;&quot;&gt;public&lt;/span&gt; QWidget, &lt;span style=&quot;color: #0000ff;&quot;&gt;private&lt;/span&gt; Ui::&lt;span style=&quot;color: #00eeff;&quot;&gt;MyWidget&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
    Q_OBJECT
&amp;nbsp;
&lt;span style=&quot;color: #0000ff;&quot;&gt;public&lt;/span&gt;:
    MyWidget&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;QWidget *parent = &lt;span style=&quot;color: #0000dd;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;;&lt;/pre&gt;


&lt;p&gt;Nous avons effectué un héritage privé, pour ne pas exposer l'interface dans les éventuelles sous-classes de notre classe. Mais nous pourrions très bien faire un héritage protégé ou publique afin qu'elle soit accessible.&lt;/p&gt;


&lt;p&gt;Là encore, il est nécessaire d'appeler la méthode &lt;code&gt;setupUi&lt;/code&gt;, mais les méthodes et les widgets sont directement accessibles dans le code du widget (il n'est plus nécessaire d'utiliser &lt;strong&gt;ui&lt;/strong&gt;)&amp;nbsp;:&lt;/p&gt;
&lt;pre class=&quot;cpp&quot;&gt;MyWidget::&lt;span style=&quot;color: #00eeff;&quot;&gt;MyWidget&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;QWidget *parent&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
    : QWidget&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;parent&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
    setupUi&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000dd;&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Personnellement, c'est ma méthode préférée&amp;nbsp;: elle offre une &lt;strong&gt;meilleure lisibilité du code&lt;/strong&gt;, par contre il n'est plus possible de modifier l'interface (mais était-ce vraiment un problème ?).&lt;/p&gt;



&lt;h3&gt;Connexions automatiques&lt;/h3&gt;


&lt;p&gt;Depuis Qt4, il n'est plus possible de créer des slots directement dans le designer et de les connecter graphiquement... il est donc nécessaire de définir la connexion dans le constructeur (comme nous l'avons fait pour la &lt;a href=&quot;http://doc.qtfr.org/post/2007/04/01/#simple&quot;&gt;méthode héritage simple&lt;/a&gt;). Mais il est possible de définir des connexions automatiques avec des noms de slots utilisant une certaine convention&amp;nbsp;:&lt;/p&gt;

&lt;pre&gt; on_&amp;lt;nom du widget&amp;gt;_&amp;lt;nom du signal&amp;gt;(&amp;lt;paramètres du signal&amp;gt;);&lt;/pre&gt;


&lt;p&gt;Lors de la compilation de la &lt;em&gt;form&lt;/em&gt; par &lt;code&gt;uic&lt;/code&gt;, il génère le code nécessaire à la création automatique des connexions. Dans notre exemple, nous aurions pu utiliser le slot suivant&amp;nbsp;:&lt;/p&gt;
&lt;pre class=&quot;cpp&quot;&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;void&lt;/span&gt; MyWidget::&lt;span style=&quot;color: #00eeff;&quot;&gt;on_pushButton_clicked&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
    ui.&lt;span style=&quot;color: #00eeff;&quot;&gt;lineEdit&lt;/span&gt;-&amp;gt;setText&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot;YEAH !!!&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;</description>
    
          <enclosure url="http://doc.qtfr.org/public/2007/designer.tar.gz"
      length="1483" type="application/x-gzip" />
    
    
      </item>
    
  <item>
    <title>Un conteneur pour MPlayer (utilisation de QProcess)</title>
    <link>http://doc.qtfr.org/post/2007/03/21/Un-conteneur-pour-MPlayer-utilisation-de-QProcess</link>
    <guid isPermaLink="false">urn:md5:afa61892107e63fea382cac105f90974</guid>
    <pubDate>Mon, 02 Apr 2007 09:01:00 +0200</pubDate>
    <dc:creator>IrmatDen</dc:creator>
        <category>Tutoriels</category>
        <category>class_QProcess</category><category>class_QWidget</category><category>intégration</category><category>MPlayer</category><category>version_PyQt4</category><category>version_Qt3</category><category>version_Qt4</category>    
    <description>&lt;ul&gt;
&lt;li&gt;Comment visualiser une vidéo dans Qt&amp;nbsp;?&lt;/li&gt;
&lt;li&gt;Comment intégrer MPlayer et Qt&amp;nbsp;?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Qt, dans son souci de framework généraliste, n'implémente pas toujours tout ce dont on peut avoir besoin, surtout lorsque cela n'est pas d'usage courant. Les vidéos font partie de ce qui n'était pas couvert par Qt (maintenant supporté depuis la 4.4 par le biais de Phonon). Cependant, un grand nombre de librairies et autres backends existent.
Nous allons voir comment utiliser l'un d'entre eux: &lt;a href=&quot;http://www.mplayerhq.hu/design7/news.html&quot;&gt;MPlayer&lt;/a&gt;.&lt;/p&gt;


&lt;p&gt;&lt;strong&gt;Version concernée&lt;/strong&gt;&amp;nbsp;: Toutes versions (exemple fait avec C++/Qt4 et une version pyQt disponible)&lt;br /&gt;
&lt;strong&gt;Auteur&lt;/strong&gt;&amp;nbsp;: Denys Bulant (&lt;a href=&quot;http://qtfr.org/forum/profile.php?id=291&quot;&gt;IrmatDen&lt;/a&gt;), &lt;a href=&quot;http://forum.qtfr.org/profile.php?id=2344&quot;&gt;alteo_gange&lt;/a&gt; et &lt;a href=&quot;http://forum.qtfr.org/profile.php?id=4253&quot;&gt;egaudrain&lt;/a&gt; pour les versions pyQt&lt;br /&gt;
&lt;strong&gt;Résumé&lt;/strong&gt;&amp;nbsp;: utiliser MPlayer conjointement à Qt pour afficher une vidéo&lt;br /&gt;
&lt;strong&gt;Fil de discussion&lt;/strong&gt;&amp;nbsp;: &lt;a href=&quot;http://forum.qtfr.org/viewtopic.php?pid=14373&quot;&gt;Forum&lt;/a&gt;&lt;/p&gt;    &lt;h3&gt;Généralité sur MPlayer en tant que backend...&lt;/h3&gt;

&lt;p&gt;La particularité de MPlayer est de ne pas s'intégrer par le biais d'une api, mais par un process externe. Les applications désirant l'utiliser en tant que tel, doivent communiquer avec lui par le biais de son flux d'entrée. Les flux de sorties (standard/erreur) peuvent bien sûr être analysés pour récupérer diverses infos sur la vidéo ainsi que les réponses à des requêtes pouvant être formulées par votre application.&lt;/p&gt;


&lt;p&gt;Voici ce dont vous aurez besoin&amp;nbsp;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://www.mplayerhq.hu/design7/dload.html&quot;&gt;MPlayer&lt;/a&gt; installé, et fonctionnel,&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.mplayerhq.hu/DOCS/man/en/mplayer.1.html&quot;&gt;La page des options de MPlayer&lt;/a&gt;,&lt;/li&gt;
&lt;li&gt;Et &lt;a href=&quot;http://www.mplayerhq.hu/DOCS/tech/slave.txt&quot;&gt;la liste des options en slave mode&lt;/a&gt; pour mplayer (c'est toutes les manip qui vous sont permises, donc considérez ce fichier comme votre référence ;)).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Pour utiliser MPlayer comme backend, il y a 2 arguments à lui passer &lt;strong&gt;impérativement&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;l'id du widget à utiliser pour le rendu par le biais de &quot;-wid&quot;&lt;/li&gt;
&lt;li&gt;&quot;-slave&quot; qui permet de le mettre en mode esclave, d'où le nom  ;-)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Exemple de code lançant MPlayer comme backend:&lt;/p&gt;
&lt;pre class=&quot;cpp&quot;&gt;QStringList args;
&lt;span style=&quot;color: #ff0000;&quot;&gt;// On demande à utiliser mplayer comme backend&lt;/span&gt;
args &amp;lt;&amp;lt; &lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot;-slave&amp;quot;&lt;/span&gt;;
&lt;span style=&quot;color: #339900;&quot;&gt;#ifdef Q_WS_WIN&lt;/span&gt;
&lt;span style=&quot;color: #ff0000;&quot;&gt;// reinterpret_cast&amp;lt;unsigned int&amp;gt; obligatoire, HWND ne se laissant pas convertir gentiment ;)&lt;/span&gt;
args &amp;lt;&amp;lt; &lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot;-wid&amp;quot;&lt;/span&gt; &amp;lt;&amp;lt; QString::&lt;span style=&quot;color: #00eeff;&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;reinterpret_cast&amp;lt;unsigned int&amp;gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;renderTarget-&amp;gt;winId&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
&lt;span style=&quot;color: #339900;&quot;&gt;#else&lt;/span&gt;
&lt;span style=&quot;color: #ff0000;&quot;&gt;// Sur linux, pas de manip pour Wid :)&lt;/span&gt;
args &amp;lt;&amp;lt; &lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot;-wid&amp;quot;&lt;/span&gt; &amp;lt;&amp;lt; QString::&lt;span style=&quot;color: #00eeff;&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;renderTarget-&amp;gt;winId&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
&lt;span style=&quot;color: #339900;&quot;&gt;#endif&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;A savoir aussi que sur Windows, je n'ai trouvé que directx comme driver de sortie :/ Cela ne concerne pas les autres OS; lors de mon test sur Linux, je n'ai eu aucun driver à spécifier et cela marche nickel.&lt;/p&gt;


&lt;p&gt;Et apparemment les seuls drivers compatibles pour un embarquement de MPlayer sous Linux sont xv, x11 et gl. Et sous Linux, il faut faire attention à avoir un widget de taille raisonnable pour contenir la vidéo. En effet, contrairement à Windows, un resize à la volée n'est pas possible :/&lt;/p&gt;


&lt;p&gt;Ensuite, le mode esclave permet donc de commander MPlayer pour:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;obtenir des infos (ex: get_video_resolution/get_time_length/...)&lt;/li&gt;
&lt;li&gt;lui donner un ordre (ex: play/pause/quit/...)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Tout ce qui lui est transmis, doit être terminé par un retour chariot. Si vous demandiez une information, elle sera renvoyée sur la sortie standard, avec un début de ligne propre à chaque commande (ex: get_video_resolution renverra &lt;code&gt;ANS_VIDEO_RESOLUTION='resX x resY'&lt;/code&gt;)&lt;/p&gt;


&lt;h3&gt;Exemple complet&lt;/h3&gt;

&lt;p&gt;&lt;img src=&quot;http://doc.qtfr.org/public/2006/previewqtmplayerui.png&quot; alt=&quot;Illustration MPlayer/Qt&quot; style=&quot;display:block; margin:0 auto;&quot; /&gt;&lt;/p&gt;


&lt;p&gt;Voici un programme proposant les fonctionnalités suivantes:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;lecture d'une vidéo&lt;/li&gt;
&lt;li&gt;arrêt&lt;/li&gt;
&lt;li&gt;avancer/reculer en déplaçant le slider&lt;/li&gt;
&lt;li&gt;affiche le log de toutes ce qui sort sur les flux stdout et stderr de mplayer&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Vous le trouverez en annexe de ce tuto&amp;nbsp;; seuls les points essentiels sont repris ici par souci de clarté.
Pour vos tests, &lt;strong&gt;pensez à changer&lt;/strong&gt; les valeurs de &lt;code&gt;mPlayerPath&lt;/code&gt; et &lt;code&gt;movieFile&lt;/code&gt;, en haut du fichier.&lt;/p&gt;


&lt;p&gt;Ce n'est pas un frontend complet, mais cela vous permettra de voir fonctionner Qt 4 avec MPlayer en utilisant &lt;code&gt;QProcess&lt;/code&gt;  :)&lt;/p&gt;


&lt;p&gt;Comme dit dans l'introduction, une version pyQt a été réalisée par &lt;a href=&quot;http://forum.qtfr.org/profile.php?id=2344&quot;&gt;alteo_gange&lt;/a&gt;. Elle est disponible sur le &lt;a href=&quot;http://forum.qtfr.org/viewtopic.php?pid=31501#p31501&quot;&gt;forum&lt;/a&gt;. A noter qu'une version multi-plateforme a été postée par &lt;a href=&quot;http://forum.qtfr.org/profile.php?id=4253&quot;&gt;egaudrain&lt;/a&gt;; le code est dispo à ce &lt;a href=&quot;http://forum.qtfr.org/viewtopic.php?pid=37823#p37823&quot;&gt;post&lt;/a&gt;.&lt;/p&gt;
&lt;pre class=&quot;cpp&quot;&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;class&lt;/span&gt; PlayerWidget: &lt;span style=&quot;color: #0000ff;&quot;&gt;public&lt;/span&gt; QWidget
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
    Q_OBJECT
&amp;nbsp;
&lt;span style=&quot;color: #0000ff;&quot;&gt;public&lt;/span&gt;:
    PlayerWidget&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;QWidget *parent =&lt;span style=&quot;color: #0000dd;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
        :QWidget&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;parent&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;, isPlaying&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;false&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#91;&lt;/span&gt;...&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#93;&lt;/span&gt;
        renderTarget = &lt;span style=&quot;color: #0000dd;&quot;&gt;new&lt;/span&gt; QWidget;
        renderTarget-&amp;gt;setSizePolicy&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;QSizePolicy&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;QSizePolicy::&lt;span style=&quot;color: #00eeff;&quot;&gt;Fixed&lt;/span&gt;, QSizePolicy::&lt;span style=&quot;color: #00eeff;&quot;&gt;Fixed&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
        renderTarget-&amp;gt;setAttribute&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;Qt::&lt;span style=&quot;color: #00eeff;&quot;&gt;WA_PaintOnScreen&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
        renderTarget-&amp;gt;setMinimumSize&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000dd;&quot;&gt;320&lt;/span&gt;, &lt;span style=&quot;color: #0000dd;&quot;&gt;240&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#91;&lt;/span&gt;...&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#93;&lt;/span&gt;
&amp;nbsp;
        mplayerProcess = &lt;span style=&quot;color: #0000dd;&quot;&gt;new&lt;/span&gt; QProcess&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000dd;&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
&amp;nbsp;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#91;&lt;/span&gt;...&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#93;&lt;/span&gt;
        connect&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;mplayerProcess, &lt;span style=&quot;color: #0000ff;&quot;&gt;SIGNAL&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;readyReadStandardOutput&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;,
            &lt;span style=&quot;color: #0000dd;&quot;&gt;this&lt;/span&gt;, SLOT&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;catchOutput&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
        connect&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;mplayerProcess, &lt;span style=&quot;color: #0000ff;&quot;&gt;SIGNAL&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;finished&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;int&lt;/span&gt;, QProcess::&lt;span style=&quot;color: #00eeff;&quot;&gt;ExitStatus&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;,
            &lt;span style=&quot;color: #0000dd;&quot;&gt;this&lt;/span&gt;, SLOT&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;mplayerEnded&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;int&lt;/span&gt;, QProcess::&lt;span style=&quot;color: #00eeff;&quot;&gt;ExitStatus&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#91;&lt;/span&gt;...&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#93;&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
&lt;span style=&quot;color: #0000ff;&quot;&gt;protected&lt;/span&gt;:
    &lt;span style=&quot;color: #0000ff;&quot;&gt;virtual&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;void&lt;/span&gt; closeEvent&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;QCloseEvent *e&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#91;&lt;/span&gt;...&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#93;&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
    &lt;span style=&quot;color: #0000ff;&quot;&gt;private&lt;/span&gt;:
    &lt;span style=&quot;color: #0000ff;&quot;&gt;bool&lt;/span&gt; startMPlayer&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#91;&lt;/span&gt;...&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#93;&lt;/span&gt;
        QStringList args;
        &lt;span style=&quot;color: #ff0000;&quot;&gt;// On demande à utiliser mplayer comme backend&lt;/span&gt;
        args &amp;lt;&amp;lt; &lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot;-slave&amp;quot;&lt;/span&gt;;
        &lt;span style=&quot;color: #ff0000;&quot;&gt;// Et on veut ne pas avoir trop de chose à parser  :) &lt;/span&gt;
        args &amp;lt;&amp;lt; &lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot;-quiet&amp;quot;&lt;/span&gt;;
&amp;nbsp;
&lt;span style=&quot;color: #339900;&quot;&gt;#ifdef Q_WS_WIN&lt;/span&gt;
        &lt;span style=&quot;color: #ff0000;&quot;&gt;// reinterpret_cast&amp;lt;qlonglong&amp;gt; obligatoire, winId() ne se laissant pas convertir gentiment ;)&lt;/span&gt;
        args &amp;lt;&amp;lt; &lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot;-wid&amp;quot;&lt;/span&gt; &amp;lt;&amp;lt; QString::&lt;span style=&quot;color: #00eeff;&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;reinterpret_cast&amp;lt;qlonglong&amp;gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;renderTarget-&amp;gt;winId&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
        args &amp;lt;&amp;lt; &lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot;-vo&amp;quot;&lt;/span&gt; &amp;lt;&amp;lt; &lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot;directx:noaccel&amp;quot;&lt;/span&gt;;
&lt;span style=&quot;color: #339900;&quot;&gt;#else&lt;/span&gt;
        &lt;span style=&quot;color: #ff0000;&quot;&gt;// Sur linux, aucun driver n'a été nécessaire et pas de manip pour Wid :)&lt;/span&gt;
        args &amp;lt;&amp;lt; &lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot;-wid&amp;quot;&lt;/span&gt; &amp;lt;&amp;lt; QString::&lt;span style=&quot;color: #00eeff;&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;renderTarget-&amp;gt;winId&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
        log-&amp;gt;append&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot;Video output driver may not be necessary for your platform. &lt;span style=&quot;color: #666666; font-weight: bold;&quot;&gt;\&lt;/span&gt;
                    Check: http://www.mplayerhq.hu/DOCS/man/en/mplayer.1.html &lt;span style=&quot;color: #666666; font-weight: bold;&quot;&gt;\&lt;/span&gt;
                    at the VIDEO OUTPUT DRIVERS section.&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
&lt;span style=&quot;color: #339900;&quot;&gt;#endif&lt;/span&gt;
&amp;nbsp;
        args &amp;lt;&amp;lt; movieFile;
        qDebug&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;args.&lt;span style=&quot;color: #00eeff;&quot;&gt;join&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;.&lt;span style=&quot;color: #00eeff;&quot;&gt;toUtf8&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
&amp;nbsp;
        &lt;span style=&quot;color: #ff0000;&quot;&gt;// On parse la stdout et stderr au même endroit, donc on demande à &amp;quot;fusionnner&amp;quot; les 2 flux&lt;/span&gt;
        mplayerProcess-&amp;gt;setProcessChannelMode&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;QProcess::&lt;span style=&quot;color: #00eeff;&quot;&gt;MergedChannels&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
        mplayerProcess-&amp;gt;start&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;mplayerPath, args&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
        &lt;span style=&quot;color: #0000ff;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;!mplayerProcess-&amp;gt;waitForStarted&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000dd;&quot;&gt;3000&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
            qDebug&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot;allez, cherche le bug :o&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
            &lt;span style=&quot;color: #0000ff;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;false&lt;/span&gt;;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
        &lt;span style=&quot;color: #ff0000;&quot;&gt;// On récupère les infos de base&lt;/span&gt;
        mplayerProcess-&amp;gt;write&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot;get_video_resolution&lt;span style=&quot;color: #666666; font-weight: bold;&quot;&gt;\n&lt;/span&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
        mplayerProcess-&amp;gt;write&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot;get_time_length&lt;span style=&quot;color: #666666; font-weight: bold;&quot;&gt;\n&lt;/span&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#91;&lt;/span&gt;...&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#93;&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
    &lt;span style=&quot;color: #0000ff;&quot;&gt;bool&lt;/span&gt; stopMPlayer&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#91;&lt;/span&gt;...&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#93;&lt;/span&gt;
        mplayerProcess-&amp;gt;write&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot;quit&lt;span style=&quot;color: #666666; font-weight: bold;&quot;&gt;\n&lt;/span&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
        &lt;span style=&quot;color: #0000ff;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;!mplayerProcess-&amp;gt;waitForFinished&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000dd;&quot;&gt;3000&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
            qDebug&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot;ZOMG, ça plante :(&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
            &lt;span style=&quot;color: #0000ff;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;false&lt;/span&gt;;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
        &lt;span style=&quot;color: #0000ff;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;true&lt;/span&gt;;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
&lt;span style=&quot;color: #0000ff;&quot;&gt;private&lt;/span&gt; slots:
    &lt;span style=&quot;color: #0000ff;&quot;&gt;void&lt;/span&gt; catchOutput&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
        &lt;span style=&quot;color: #0000ff;&quot;&gt;while&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;mplayerProcess-&amp;gt;canReadLine&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
            QByteArray buffer&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;mplayerProcess-&amp;gt;readLine&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
            log-&amp;gt;append&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;QString&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;buffer&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
&amp;nbsp;
            &lt;span style=&quot;color: #ff0000;&quot;&gt;// On vérifie si on a eu des réponses&lt;/span&gt;
            &lt;span style=&quot;color: #ff0000;&quot;&gt;// réponse à get_video_resolution : ANS_VIDEO_RESOLUTION='176 x 144'&lt;/span&gt;
            &lt;span style=&quot;color: #0000ff;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;buffer.&lt;span style=&quot;color: #00eeff;&quot;&gt;startsWith&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot;ANS_VIDEO_RESOLUTION&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
            &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
                buffer.&lt;span style=&quot;color: #0000dd;&quot;&gt;remove&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000dd;&quot;&gt;0&lt;/span&gt;, &lt;span style=&quot;color: #0000dd;&quot;&gt;21&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
                buffer.&lt;span style=&quot;color: #00eeff;&quot;&gt;replace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;QByteArray&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot;'&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;, QByteArray&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
                buffer.&lt;span style=&quot;color: #00eeff;&quot;&gt;replace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;QByteArray&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;, QByteArray&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
                buffer.&lt;span style=&quot;color: #00eeff;&quot;&gt;replace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;QByteArray&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot;&lt;span style=&quot;color: #666666; font-weight: bold;&quot;&gt;\n&lt;/span&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;, QByteArray&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
                buffer.&lt;span style=&quot;color: #00eeff;&quot;&gt;replace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;QByteArray&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot;&lt;span style=&quot;color: #666666; font-weight: bold;&quot;&gt;\r&lt;/span&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;, QByteArray&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
                &lt;span style=&quot;color: #0000ff;&quot;&gt;int&lt;/span&gt; sepIndex = buffer.&lt;span style=&quot;color: #00eeff;&quot;&gt;indexOf&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #666666;&quot;&gt;'x'&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
                &lt;span style=&quot;color: #0000ff;&quot;&gt;int&lt;/span&gt; resX = buffer.&lt;span style=&quot;color: #00eeff;&quot;&gt;left&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;sepIndex&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;.&lt;span style=&quot;color: #00eeff;&quot;&gt;toInt&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
                &lt;span style=&quot;color: #0000ff;&quot;&gt;int&lt;/span&gt; resY = buffer.&lt;span style=&quot;color: #00eeff;&quot;&gt;mid&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;sepIndex&lt;span style=&quot;color: #0000dd;&quot;&gt;+1&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;.&lt;span style=&quot;color: #00eeff;&quot;&gt;toInt&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
                renderTarget-&amp;gt;setMinimumSize&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;resX, resY&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
            &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
            &lt;span style=&quot;color: #ff0000;&quot;&gt;// réponse à get_time_length : ANS_LENGTH=45.28&lt;/span&gt;
            &lt;span style=&quot;color: #0000ff;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;buffer.&lt;span style=&quot;color: #00eeff;&quot;&gt;startsWith&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot;ANS_LENGTH&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
            &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
                buffer.&lt;span style=&quot;color: #0000dd;&quot;&gt;remove&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000dd;&quot;&gt;0&lt;/span&gt;, &lt;span style=&quot;color: #0000dd;&quot;&gt;11&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
                buffer.&lt;span style=&quot;color: #00eeff;&quot;&gt;replace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;QByteArray&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot;'&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;, QByteArray&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
                buffer.&lt;span style=&quot;color: #00eeff;&quot;&gt;replace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;QByteArray&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;, QByteArray&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
                buffer.&lt;span style=&quot;color: #00eeff;&quot;&gt;replace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;QByteArray&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot;&lt;span style=&quot;color: #666666; font-weight: bold;&quot;&gt;\n&lt;/span&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;, QByteArray&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
                buffer.&lt;span style=&quot;color: #00eeff;&quot;&gt;replace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;QByteArray&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot;&lt;span style=&quot;color: #666666; font-weight: bold;&quot;&gt;\r&lt;/span&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;, QByteArray&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
                &lt;span style=&quot;color: #0000ff;&quot;&gt;float&lt;/span&gt; maxTime = buffer.&lt;span style=&quot;color: #00eeff;&quot;&gt;toFloat&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
                timeLine-&amp;gt;setMaximum&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;static_cast&amp;lt;int&amp;gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;maxTime&lt;span style=&quot;color: #0000dd;&quot;&gt;+1&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
            &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
            &lt;span style=&quot;color: #ff0000;&quot;&gt;// réponse à get_time_pos : ANS_TIME_POSITION=2.4&lt;/span&gt;
            &lt;span style=&quot;color: #0000ff;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;buffer.&lt;span style=&quot;color: #00eeff;&quot;&gt;startsWith&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot;ANS_TIME_POSITION&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
            &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
                buffer.&lt;span style=&quot;color: #0000dd;&quot;&gt;remove&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000dd;&quot;&gt;0&lt;/span&gt;, &lt;span style=&quot;color: #0000dd;&quot;&gt;18&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
                buffer.&lt;span style=&quot;color: #00eeff;&quot;&gt;replace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;QByteArray&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot;'&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;, QByteArray&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
                buffer.&lt;span style=&quot;color: #00eeff;&quot;&gt;replace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;QByteArray&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;, QByteArray&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
                buffer.&lt;span style=&quot;color: #00eeff;&quot;&gt;replace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;QByteArray&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot;&lt;span style=&quot;color: #666666; font-weight: bold;&quot;&gt;\n&lt;/span&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;, QByteArray&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
                buffer.&lt;span style=&quot;color: #00eeff;&quot;&gt;replace&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;QByteArray&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot;&lt;span style=&quot;color: #666666; font-weight: bold;&quot;&gt;\r&lt;/span&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;, QByteArray&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
                &lt;span style=&quot;color: #0000ff;&quot;&gt;float&lt;/span&gt; currTime = buffer.&lt;span style=&quot;color: #00eeff;&quot;&gt;toFloat&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
                timeLine-&amp;gt;setValue&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;static_cast&amp;lt;int&amp;gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;currTime&lt;span style=&quot;color: #0000dd;&quot;&gt;+1&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
            &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
    &lt;span style=&quot;color: #0000ff;&quot;&gt;void&lt;/span&gt; pollCurrentTime&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
        mplayerProcess-&amp;gt;write&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot;get_time_pos&lt;span style=&quot;color: #666666; font-weight: bold;&quot;&gt;\n&lt;/span&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
    &lt;span style=&quot;color: #ff0000;&quot;&gt;// Dirige la timeline&lt;/span&gt;
    &lt;span style=&quot;color: #0000ff;&quot;&gt;void&lt;/span&gt; timeLineChanged&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;int&lt;/span&gt; pos&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
        mplayerProcess-&amp;gt;write&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;QString&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot;seek &amp;quot;&lt;/span&gt; + QString::&lt;span style=&quot;color: #00eeff;&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;pos&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; + &lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot; 2&lt;span style=&quot;color: #666666; font-weight: bold;&quot;&gt;\n&lt;/span&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;.&lt;span style=&quot;color: #00eeff;&quot;&gt;toUtf8&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
    &lt;span style=&quot;color: #ff0000;&quot;&gt;// Play/stop&lt;/span&gt;
    &lt;span style=&quot;color: #0000ff;&quot;&gt;void&lt;/span&gt; switchPlayState&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#91;&lt;/span&gt;...&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#93;&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
    &lt;span style=&quot;color: #0000ff;&quot;&gt;void&lt;/span&gt; mplayerEnded&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;int&lt;/span&gt; exitCode, QProcess::&lt;span style=&quot;color: #00eeff;&quot;&gt;ExitStatus&lt;/span&gt; exitStatus&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#91;&lt;/span&gt;...&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#93;&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
&lt;span style=&quot;color: #0000ff;&quot;&gt;private&lt;/span&gt;:
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#91;&lt;/span&gt;...&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#93;&lt;/span&gt;
    QWidget *renderTarget;
    QProcess *mplayerProcess;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#91;&lt;/span&gt;...&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#93;&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;;&lt;/pre&gt;


&lt;h3&gt;Si vous avez des remarques...&lt;/h3&gt;

&lt;p&gt;Si vous avez besoin d'un éclaircissement, vous pouvez le faire &lt;a href=&quot;http://qtfr.org/forum/viewtopic.php?pid=14373#p14373&quot;&gt;ici&lt;/a&gt;.&lt;/p&gt;</description>
    
          <enclosure url="http://doc.qtfr.org/public/2007/qt_mplayer.tar.gz"
      length="2452" type="application/x-gzip" />
    
    
      </item>
    
  <item>
    <title>Compiler Qt 4 avec Visual C++ 2005</title>
    <link>http://doc.qtfr.org/post/2007/03/26/Compiler-Qt-4-avec-Visual-C-2005</link>
    <guid isPermaLink="false">urn:md5:3b6dac9b1e7e567528e9b64b47c264ef</guid>
    <pubDate>Mon, 26 Mar 2007 21:14:00 +0200</pubDate>
    <dc:creator>Visiteur</dc:creator>
        <category>Installation</category>
        <category>installation</category><category>version_Qt4</category><category>Windows</category>    
    <description>&lt;ul&gt;
&lt;li&gt;Installation de Qt4 avec Visual C++ 2005&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;La version Open-Source de Qt4 n'est compatible &lt;em&gt;officiellement&lt;/em&gt; sous Windows qu'avec le compilateur &lt;a href=&quot;http://www.mingw.org/&quot; hreflang=&quot;en&quot;&gt;mingw&lt;/a&gt;. Il est toutefois possible d'utiliser Visual C++.&lt;/p&gt;


&lt;p&gt;Sachez toutefois que &lt;strong&gt;cette installation n'est pas supporté officiellement&lt;/strong&gt;.&lt;/p&gt;


&lt;p&gt;&lt;strong&gt;Auteur&lt;/strong&gt;&amp;nbsp;: &lt;a href=&quot;http://arb.developpez.com/&quot;&gt;Aurélien Regat-Barrel&lt;/a&gt; &lt;br /&gt;
&lt;strong&gt;Version&lt;/strong&gt;&amp;nbsp;: Qt4 Windows &lt;br /&gt;
&lt;strong&gt;Test&lt;/strong&gt;&amp;nbsp;: Qt 4.1.1&lt;/p&gt;    &lt;p&gt;L'article est disponible sur le site de &lt;strong&gt;developpez.com&lt;/strong&gt;&amp;nbsp;: &lt;a href=&quot;http://arb.developpez.com/qt4/vc++/compilation/&quot; title=&quot;http://arb.developpez.com/qt4/vc++/compilation/&quot;&gt;http://arb.developpez.com/qt4/vc++/...&lt;/a&gt;&lt;/p&gt;


&lt;blockquote&gt;&lt;p&gt;Cet article a pour but de faciliter la compilation Qt/Windows Open Source Edition avec Microsoft Visual C++ 2005. Il présente aussi de manière détaillée le processus de compilation et le principe de configuration de cette bibliothèque.&lt;/p&gt;&lt;/blockquote&gt;


&lt;p&gt;Vous trouverez également un article sur notre forum&amp;nbsp;: &lt;a href=&quot;http://forum.qtfr.org/viewtopic.php?id=1531&quot; title=&quot;http://forum.qtfr.org/viewtopic.php?id=1531&quot;&gt;http://forum.qtfr.org/viewtopic.php...&lt;/a&gt;&lt;/p&gt;</description>
    
    
    
      </item>
    
  <item>
    <title>Qt4 et C++ : Programmation d'interfaces GUI</title>
    <link>http://doc.qtfr.org/post/2007/03/15/Qt4-et-C-%3A-Programmation-dinterfaces-GUI</link>
    <guid isPermaLink="false">urn:md5:380957e1037de501b1bbbcabf9f05043</guid>
    <pubDate>Thu, 15 Mar 2007 14:03:00 +0100</pubDate>
    <dc:creator>Nicolas</dc:creator>
        <category>Livres</category>
        <category>livre</category><category>version_Qt4</category>    
    <description>&lt;p&gt;Livre officiel de Trolltech pour la programmation Qt (version 4.1), ce livre est la traduction française de &lt;strong&gt;C++ GUI Programming with Qt 4&lt;/strong&gt;. Il aborde tous les aspects de la bibliothèque&amp;nbsp;: organisation des widgets, évènements, programmation 2D et 3D...&lt;/p&gt;


&lt;p&gt;C'est &lt;strong&gt;le livre de référence français&lt;/strong&gt; sur la programmation Qt4.&lt;/p&gt;    &lt;p&gt;&lt;a href=&quot;http://www.pearsoned.fr/espace/livre.asp?idEspace=73&amp;amp;idLivre=2850&amp;amp;dep=0&quot;&gt;&lt;img src=&quot;http://doc.qtfr.org/public/livres/programmation-qt4.jpg&quot; alt=&quot;programmation-qt4.jpg&quot; style=&quot;float:right; margin: 0 0 1em 1em;&quot; /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;Informations&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;em&gt;Auteurs&lt;/em&gt;&amp;nbsp;: Jasmin Blanchette et Mark Summerfield&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Editeur&lt;/em&gt;&amp;nbsp;: &lt;a href=&quot;http://www.pearsoned.fr/home/default.asp&quot; hreflang=&quot;fr&quot;&gt;Pearson Education France&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Collection&lt;/em&gt;&amp;nbsp;: &lt;a href=&quot;http://www.pearsoned.fr/espace/livre.asp?idEspace=73&amp;amp;idLivre=2850&amp;amp;dep=0&quot; hreflang=&quot;fr&quot;&gt;CampusPress | Référence&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Langue&lt;/em&gt;&amp;nbsp;: français&lt;/li&gt;
&lt;li&gt;&lt;em&gt;ISBN&lt;/em&gt;&amp;nbsp;: 9782744021404&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Pages&lt;/em&gt;&amp;nbsp;: 570&lt;/li&gt;
&lt;/ul&gt;


&lt;h3&gt;Résumé&lt;/h3&gt;


&lt;p&gt;Voici la traduction française de l'excellent livre &lt;strong&gt;C++ GUI Programming with Qt 4&lt;/strong&gt;, écrit par des experts de la bibliothèque Qt.&lt;/p&gt;


&lt;p&gt;Ce livre couvre tous les aspects de la programmation Qt, avec une première partie offrant une approche simple pour le débutant, en détaillant pas à pas la création d'une application complète. La seconde partie détaille les différents aspects de la bibliothèque&amp;nbsp;: organisation des widgets, évènements, programmation 2D et 3D... Enfin, la dernière partie aborde des aspects plus complexes&amp;nbsp;: internationalisation, multi-threading.&lt;/p&gt;


&lt;p&gt;Le CD comporte les versions GPL de Qt 4.1.1 sous Windows/Linux/Mac OSX.&lt;/p&gt;


&lt;p&gt;Un chapitre du livre est actuellement en &lt;strong&gt;libre téléchargement en PDF&lt;/strong&gt; sur le site de &lt;a href=&quot;http://www.pearsoned.fr/espace/livre.asp?idEspace=73&amp;amp;amp;idLivre=2850&amp;amp;amp;dep=0&quot; hreflang=&quot;fr&quot;&gt;Pearson Education France&lt;/a&gt; (ou en annexe ici).&lt;/p&gt;



&lt;h3&gt;Table des matières&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Partie I&amp;nbsp;: Qt&amp;nbsp;: notions de base
&lt;ul&gt;
&lt;li&gt;Pour débuter&lt;/li&gt;
&lt;li&gt;Créer des boîtes de dialogue (A télécharger)&lt;/li&gt;
&lt;li&gt;Créer des fenêtres principales&lt;/li&gt;
&lt;li&gt;Implémenter la fonctionnalité d'application&lt;/li&gt;
&lt;li&gt;Créer des widgets personnalisés&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;Partie II&amp;nbsp;: Qt&amp;nbsp;: niveau intermédiaire
&lt;ul&gt;
&lt;li&gt;Gestion des dispositions&lt;/li&gt;
&lt;li&gt;Traitement des événements&lt;/li&gt;
&lt;li&gt;Graphiques 2D et 3D&lt;/li&gt;
&lt;li&gt;Glisser-déposer&lt;/li&gt;
&lt;li&gt;Classes d'affichage d'éléments&lt;/li&gt;
&lt;li&gt;Classes conteneur&lt;/li&gt;
&lt;li&gt;Entrées/sorties&lt;/li&gt;
&lt;li&gt;Les bases de données&lt;/li&gt;
&lt;li&gt;Gestion de réseau&lt;/li&gt;
&lt;li&gt;XML&lt;/li&gt;
&lt;li&gt;Aide en ligne&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;Partie III&amp;nbsp;: Qt&amp;nbsp;: étude avancée
&lt;ul&gt;
&lt;li&gt;Internationalisation&lt;/li&gt;
&lt;li&gt;Environnement multithread&lt;/li&gt;
&lt;li&gt;Création de plug-in&lt;/li&gt;
&lt;li&gt;Fonctionnalités spécifiques à la plate-forme&lt;/li&gt;
&lt;li&gt;Programmation embarquée&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;/ul&gt;</description>
    
          <enclosure url="http://doc.qtfr.org/public/livres/programmation-qt4-C2.pdf"
      length="1253400" type="application/pdf" />
    
    
      </item>
    
  <item>
    <title>Intégration de VLC</title>
    <link>http://doc.qtfr.org/post/2007/02/21/Integration-de-VLC</link>
    <guid isPermaLink="false">urn:md5:65c3d5b954ca0f9de7cf8e553dab58a0</guid>
    <pubDate>Wed, 21 Feb 2007 22:55:00 +0100</pubDate>
    <dc:creator>lud42fr</dc:creator>
        <category>Tutoriels</category>
        <category>class_QWidget</category><category>intégration</category><category>version_Qt3</category><category>version_Qt4</category><category>VLC</category>    
    <description>&lt;ul&gt;
&lt;li&gt;Comment intégrer VLC dans une application Qt&amp;nbsp;?&lt;/li&gt;
&lt;li&gt;Comment visualiser une vidéo dans une applicaiton Qt&amp;nbsp;?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Ce tutoriel va explorer l'intégration de la bibliothèque VLC dans Qt, pour la lecture de fichier.&lt;/p&gt;


&lt;p&gt;&lt;strong&gt;Version&lt;/strong&gt;&amp;nbsp;: Qt3, Qt4 &lt;br /&gt;
&lt;strong&gt;Auteur&lt;/strong&gt;&amp;nbsp;: Ludo (&lt;a href=&quot;http://forum.qtfr.org/profile.php?id=1041&quot;&gt;lud42fr&lt;/a&gt;) &lt;br /&gt;
&lt;strong&gt;Status&lt;/strong&gt;&amp;nbsp;: basé sur la version SVN 0.9.0 de l’API VLC (devrait egalement fonctionner avec une version &amp;gt;= 0.8.6)&lt;/p&gt;    &lt;h3&gt;Introduction&lt;/h3&gt;


&lt;p&gt;Qt, dans son souci de framework généraliste, n’implémente pas toujours tout ce dont on peut avoir besoin, surtout lorsque cela n’est pas d’usage courant. Les vidéos font partie de ce qui n’est pas couvert par Qt. Cependant, un grand nombre de librairies et autres backends existent. Nous allons voir comment utiliser l’une d’entre elle: &lt;a href=&quot;http://www.videolan.org/&quot; hreflang=&quot;en&quot;&gt;VLC&lt;/a&gt;.&lt;/p&gt;



&lt;h3&gt;Pré-requis&lt;/h3&gt;


&lt;p&gt;Voici ce dont vous aurez besoin&amp;nbsp;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Les librairies VLC &amp;gt;= 0.8.6 &lt;a href=&quot;http://www.videolan.org/vlc/&quot; hreflang=&quot;en&quot;&gt;(Page de téléchargement)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;La documentation des &lt;a href=&quot;http://www.videolan.org/developers/vlc/doc/doxygen/html/modules.html&quot; title=&quot;en&quot;&gt;fonctions internes de VLC&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Il semblerait que VLC soit &lt;em&gt;difficilement compilable sous Visual C++&lt;/em&gt;. Comme ce tutoriel suppose de pouvoir lier votre application avec les libraires VLC, les personnes désireuses de développer sous Windows devront utiliser Mingw pour générer leur application.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Pour compiler VLC 0.9.0 (la version actuellement en cours de développement, récupérable depuis le SVN), vous aurez besoin de&amp;nbsp;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;bibliothèque MAD (MPEG Audio Decoder)&amp;nbsp;: &lt;a href=&quot;http://www.underbit.com/products/mad/&quot; title=&quot;http://www.underbit.com/products/mad/&quot;&gt;http://www.underbit.com/products/ma...&lt;/a&gt; ou mettre une option lors du &lt;code&gt;configure&lt;/code&gt; pour la désactiver,&lt;/li&gt;
&lt;li&gt;FFMpeg&amp;nbsp;: &lt;a href=&quot;http://ffmpeg.mplayerhq.hu/&quot; title=&quot;http://ffmpeg.mplayerhq.hu/&quot;&gt;http://ffmpeg.mplayerhq.hu/&lt;/a&gt;,&lt;/li&gt;
&lt;li&gt;liba52&amp;nbsp;: &lt;a href=&quot;http://liba52.sf.net&quot; title=&quot;http://liba52.sf.net&quot;&gt;http://liba52.sf.net&lt;/a&gt;,&lt;/li&gt;
&lt;li&gt;libmpeg2&amp;nbsp;: &lt;a href=&quot;http://libmpeg2.sf.net&quot; title=&quot;http://libmpeg2.sf.net&quot;&gt;http://libmpeg2.sf.net&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;


&lt;h3&gt;Lecteur vidéo&lt;/h3&gt;


&lt;p&gt;Ce tutoriel détaille la manière d'utiliser l'API VLC au travers d'une application Qt.&lt;/p&gt;


&lt;p&gt;L’avantage de cette méthode est que le contrôle de VLC est plus simple et précis et ne nécessite pas d’exécuter/piloter un processus externe (contrairement à l'utilisation de MPlayer).&lt;/p&gt;


&lt;p&gt;Nous allons créer un petit exemple simple de lecteur vidéo, ce dernier permettant&amp;nbsp;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;d’initialiser VLC,&lt;/li&gt;
&lt;li&gt;de charger un flux vidéo,&lt;/li&gt;
&lt;li&gt;de naviguer dans la vidéo (avance/retour),&lt;/li&gt;
&lt;li&gt;de modifier le volume.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Une image valant mieux qu'un long discours, voici une capture d'écran du résultat final&amp;nbsp;:&lt;/p&gt;


&lt;p&gt;&lt;a href=&quot;http://doc.qtfr.org/public/2006/vlc.jpg&quot;&gt;&lt;img src=&quot;http://doc.qtfr.org/public/2006/.vlc_m.jpg&quot; alt=&quot;vlc.jpg&quot; style=&quot;display:block; margin:0 auto;&quot; /&gt;&lt;/a&gt;&lt;/p&gt;


&lt;p&gt;&lt;a href=&quot;http://doc.qtfr.org/public/2007/qt_vlc.zip&quot;&gt;Le code de ce tutorial (source + .pro)&lt;/a&gt;&lt;/p&gt;


&lt;h4&gt;Compilation&lt;/h4&gt;


&lt;p&gt;La compilation de l’exemple nécessite bien entendu les includes et les libraires de VLC.
Celles ci doivent êtres dans dans les chemins de recherche&lt;/p&gt;


&lt;h5&gt;Linux/Unix&lt;/h5&gt;


&lt;p&gt;Voici le fichier pro typique&amp;nbsp;:&lt;/p&gt;
&lt;pre&gt;
TEMPLATE = app
DEPENDPATH += .
INCLUDEPATH += . 
SOURCES += tuto_vlc.cpp
LIBS+=-lvlc
&lt;/pre&gt;



&lt;h3&gt;Explications&lt;/h3&gt;


&lt;p&gt;Si l'on résume les étapes nécessaires à la lecture d'un vidéo dans une application Qt&amp;nbsp;:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;initialiser un contexte VLC,&lt;/li&gt;
&lt;li&gt;ajouter un flux à la playlist,&lt;/li&gt;
&lt;li&gt;rediriger la fenêtre vidéo de sortie vlc sur un widget Qt de l'application,&lt;/li&gt;
&lt;li&gt;démarrer la lecture du flux.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Certaines fonctions de l'API de VLC seront détaillées. Toutes ces fonctions et bien plus encore sont disponibles dans la &lt;a href=&quot;http://www.videolan.org/developers/vlc/doc/doxygen/html/modules.html&quot; hreflang=&quot;en&quot;&gt;documentation de VLC&lt;/a&gt;.&lt;/p&gt;



&lt;h4&gt;Initialisation d'un contexte VLC&lt;/h4&gt;


&lt;p&gt;Normalement seule l'inclusion de l'entête vlc/libvlc.h est nécessaire pour utiliser toutes les fonctions VLC.&lt;/p&gt;


&lt;pre&gt;#include &amp;lt;vlc/libvlc.h&amp;gt;&lt;/pre&gt;


&lt;p&gt;VLC reporte toutes ses erreurs dans une structure particulière &lt;code&gt;libvlc_exception_t&lt;/code&gt;. Avant tout appel à une fonction VLC, il nous faudra donc une telle structure&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;cpp&quot;&gt;libvlc_exception_t _vlcexcep; &lt;span style=&quot;color: #ff0000;&quot;&gt;//déclaration de la structure&lt;/span&gt;
libvlc_exception_init &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&amp;amp;_vlcexcep&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;; &lt;span style=&quot;color: #ff0000;&quot;&gt;//initialisation de la structure&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Quelques fonctions pratiques à utiliser avec &lt;code&gt;libvlc_exception_t&lt;/code&gt;&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;cpp&quot;&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;libvlc_exception_raised&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&amp;amp;_vlcexcep&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;!=&lt;span style=&quot;color: #0000dd;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;....&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;//teste si une erreur a eu lieu.&lt;/span&gt;
libvlc_exception_get_message&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&amp;amp;_vlcexcep&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;; &lt;span style=&quot;color: #ff0000;&quot;&gt;//retourne le message d'erreur&lt;/span&gt;
libvlc_exception_clear&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&amp;amp;_vlcexcep&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;; &lt;span style=&quot;color: #ff0000;&quot;&gt;//efface la/les erreurs précédentes&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Il est maintenant temps de créer un contexte VLC, de type &lt;code&gt;libvlc_instance_t&lt;/code&gt;, nécessaire à la plupart des fonctions&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;cpp&quot;&gt;libvlc_instance_t *_vlcinstance;
_vlcinstance=libvlc_new&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;argc,argv,&amp;amp;_vlcexcep&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;/pre&gt;


&lt;p&gt;Il n'est possible de lire qu'un seul flux vidéo à la fois par contexte. Pour lire plusieurs flux en parallèle, il faut donc initialiser plusieurs contextes. Lorsqu'un contexte, n'est plus utile, ne pas oublier de le libérer&amp;nbsp;:&lt;/p&gt;


&lt;pre&gt;libvlc_destroy (_vlcinstance, &amp;amp;_vlcexcep);&lt;/pre&gt;



&lt;h4&gt;Ajout d'un flux&lt;/h4&gt;


&lt;p&gt;Le chargement d'un flux vidéo se fait dans un contexte initialisé et dans l'élément playlist de VLC (se réfèrer à la doc quant à la gestion des playlist, ce tutoriel n'en faisant pas d'autres mentions).&lt;/p&gt;

&lt;pre class=&quot;cpp&quot;&gt;libvlc_playlist_clear&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;_vlcinstance,&amp;amp;_vlcexcep&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;; &lt;span style=&quot;color: #ff0000;&quot;&gt;//on vide la playlist&lt;/span&gt;
libvlc_playlist_add &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;_vlcinstance,URL,&lt;span style=&quot;color: #0000ff;&quot;&gt;NULL&lt;/span&gt;,&amp;amp;_vlcexcep&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;span style=&quot;color: #ff0000;&quot;&gt;//on ajoute le nouveau flux&lt;/span&gt;&lt;/pre&gt;


&lt;blockquote&gt;&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;&amp;nbsp;: à ce niveau, le fichier est dans la playlist, il n'est pas en cours de lecture ou n'a pas interrompu la lecture en cours.&lt;/p&gt;&lt;/blockquote&gt;


&lt;p&gt;Avec URL une chaine de caractère de la forme (principalement)&amp;nbsp;:&lt;/p&gt;

&lt;table&gt;
&lt;tr&gt;&lt;th&gt;Type&lt;/th&gt;          &lt;th&gt;Forme&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Fichier local&lt;/td&gt; &lt;td&gt;file://chemin&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Url http&lt;/td&gt;      &lt;td&gt;http://ip:port/file&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Fichier ftp&lt;/td&gt;   &lt;td&gt;ftp://ip:port/file&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;DVD&lt;/td&gt;           &lt;td&gt;dvd://[device]&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Flux UDP&lt;/td&gt;      &lt;td&gt;udp:[&lt;source address=&quot;&quot;&gt;]@[&lt;bind address=&quot;&quot;&gt;][:&lt;bind port=&quot;&quot;&gt;]%% &lt;/bind&gt;&lt;/bind&gt;&lt;/source&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;




&lt;h4&gt;Redirection du flux sur un widget Qt&lt;/h4&gt;


&lt;p&gt;La redirection de la sortie vidéo sur un widget de l'application est une des étapes les plus importantes pour l'intégration (ce n'est pas la plus compliquée ;-) ).&lt;/p&gt;


&lt;p&gt;A noter que VLC, se chargera d'adapter la taille de la vidéo à la taille du widget tout en conservant l'aspect de la video (VLC se chargera aussi de resizer la video si la taille du widget venait a changer en cours de lecture).&lt;/p&gt;


&lt;p&gt;N'importe quel widget peut servir pour afficher une video, mais dans la mesure ou il sera complètement recouvert, un simple &lt;code&gt;QWidget&lt;/code&gt; suffit.&lt;/p&gt;


&lt;pre&gt;//Notez l'usage de Widget-&amp;gt;winId() pour indiquer on dessiner la video
libvlc_video_set_parent(_vlcinstance ,Widget-&amp;gt;winId(),&amp;amp;_vlcexcep);&lt;/pre&gt;



&lt;h4&gt;Functions vidéos/audios&lt;/h4&gt;


&lt;p&gt;Certaines fonctions requièrent un pointeur sur libvlc_input_t .Pour obtenir ce pointeur, un flux doit etre en cours de lecture/pause&amp;nbsp;:&lt;/p&gt;


&lt;pre&gt;libvlc_input_t *input=libvlc_playlist_get_input (_vlcinstance,&amp;amp;_vlcexcep); //obtenir un pointeur input
libvlc_input_free (input); //il est en general de bon ton de libérer input après usage&lt;/pre&gt;



&lt;h5&gt;Contrôle de la vidéo&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;Démarrer la lecture&amp;nbsp;:&lt;/li&gt;
&lt;/ul&gt;

&lt;pre&gt;libvlc_playlist_play (_vlcinstance , -1, 0, NULL, &amp;amp;_vlcexcep);
// avec :
//          -1 pour indiquer de lire l'element suivant de la playlist
//          0 le nombre d'option a passer au flux a lire
//          NULL : les options&lt;/pre&gt;

&lt;ul&gt;
&lt;li&gt;Stopper la lecture&amp;nbsp;:&lt;/li&gt;
&lt;/ul&gt;

&lt;pre&gt;libvlc_playlist_stop (_vlcinstance, &amp;amp;_vlcexcep);&lt;/pre&gt;

&lt;ul&gt;
&lt;li&gt;Mettre en pause la lecture&amp;nbsp;:&lt;/li&gt;
&lt;/ul&gt;

&lt;pre&gt;libvlc_playlist_pause (_vlcinstance, &amp;amp;_vlcexcep);&lt;/pre&gt;

&lt;ul&gt;
&lt;li&gt;Connaître l'état&amp;nbsp;:&lt;/li&gt;
&lt;/ul&gt;

&lt;pre&gt;int etat=libvlc_playlist_isplaying(_vlcinstance, &amp;amp;_vlcexcep);
//etat=0 si stop ou pause
//etat=1 si lecture en cours&lt;/pre&gt;

&lt;ul&gt;
&lt;li&gt;Lire en boucle&amp;nbsp;:&lt;/li&gt;
&lt;/ul&gt;

&lt;pre&gt;int loop=1; //mettre a 0 pour stopper la lecture en boucle
libvlc_playlist_loop (_vlcinstance, loop,&amp;amp;_vlcexcep);&lt;/pre&gt;

&lt;ul&gt;
&lt;li&gt;Connaître la durée totale du flux (nécessite un pointeur input)&amp;nbsp;:&lt;/li&gt;
&lt;/ul&gt;

&lt;pre&gt;long long duree=libvlc_input_get_length (input, &amp;amp;_vlcexcep);&lt;/pre&gt;

&lt;ul&gt;
&lt;li&gt;Connaître la position actuelle en ms (nécessite un pointeur input)&amp;nbsp;:&lt;/li&gt;
&lt;/ul&gt;

&lt;pre&gt;long long position=libvlc_input_get_time (input, &amp;amp;_vlcexcep);&lt;/pre&gt;

&lt;ul&gt;
&lt;li&gt;Se positionner dans le flux (position en ms - nécessite un pointeur input)&amp;nbsp;:&lt;/li&gt;
&lt;/ul&gt;

&lt;pre&gt;libvlc_input_set_time (input, 42000,&amp;amp;_vlcexcep); //se positionne a 42 sec&lt;/pre&gt;

&lt;ul&gt;
&lt;li&gt;Connaître la position actuelle en pourcentage (nécessite un pointeur input)&amp;nbsp;:&lt;/li&gt;
&lt;/ul&gt;

&lt;pre&gt;float posEnPourcent=libvlc_input_get_position (input, &amp;amp;_vlcexcep)*100.0;&lt;/pre&gt;

&lt;ul&gt;
&lt;li&gt;Se positionner dans le flux (position en pourcentage du temps total - nécessite un pointeur input)&amp;nbsp;:&lt;/li&gt;
&lt;/ul&gt;

&lt;pre&gt;libvlc_input_set_position(input, 0.42f,&amp;amp;_vlcexcep); // se positionne a 42% du flux ???&lt;/pre&gt;



&lt;h5&gt;Contrôle du volume&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;Obtenir la valeur du volume comprise entre 0 et 100 - 0 étant le minimum&amp;nbsp;:&lt;/li&gt;
&lt;/ul&gt;

&lt;pre&gt;int volume=libvlc_audio_get_volume (_vlcinstance, &amp;amp;_vlcexcep);&lt;/pre&gt;

&lt;ul&gt;
&lt;li&gt;Positionner le volume (valeur en 0 et 100)&amp;nbsp;:&lt;/li&gt;
&lt;/ul&gt;

&lt;pre&gt;libvlc_audio_set_volume (_vlcinstance, 42,&amp;amp;_vlcexcep); //volume a 42%&lt;/pre&gt;</description>
    
          <enclosure url="http://doc.qtfr.org/public/2007/qt_vlc.zip"
      length="2792" type="application/zip" />
    
    
      </item>
    
  <item>
    <title>Intégration de SDL</title>
    <link>http://doc.qtfr.org/post/2007/02/21/Integration-de-SDL</link>
    <guid isPermaLink="false">urn:md5:117b6f909d42194f825db6c03e8c805c</guid>
    <pubDate>Wed, 21 Feb 2007 13:11:00 +0100</pubDate>
    <dc:creator>IrmatDen</dc:creator>
        <category>Tutoriels</category>
        <category>class_QWidget</category><category>intégration</category><category>SDL</category><category>version_Qt3</category><category>version_Qt4</category>    
    <description>&lt;ul&gt;
&lt;li&gt;Comment intégrer SDL dans un widget Qt&amp;nbsp;?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Ce tutoriel va explorer l'intégration de la bibliothèque SDL dans Qt, le rendu étant effectué dans un widget Qt.&lt;/p&gt;


&lt;p&gt;&lt;strong&gt;Version&lt;/strong&gt;&amp;nbsp;: Qt4 (Qt3 possible avec quelques ajustements) &lt;br /&gt;
&lt;strong&gt;Auteur&lt;/strong&gt;&amp;nbsp;: Denys Bulant (&lt;a href=&quot;http://forum.qtfr.org/profile.php?id=291&quot;&gt;IrmatDen&lt;/a&gt;)&lt;/p&gt;    &lt;h3&gt;Pré requis:&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://www.libsdl.org/&quot; hreflang=&quot;en&quot;&gt;La librairie SDL&lt;/a&gt;&amp;nbsp;: le site contient une section documentation pour débuter&lt;/li&gt;
&lt;/ul&gt;


&lt;h3&gt;Un widget Qt comme cible de rendu pour SDL&lt;/h3&gt;


&lt;p&gt;Les moteurs graphiques des différents Qt ne sont souvent pas adaptés au travail graphique intense (sauf à passer par OpenGL, mais on détourne le problème - c'est d'ailleurs ce que l'on va faire ici).&lt;/p&gt;


&lt;h4&gt;Signifier à SDL la fenêtre à utiliser&lt;/h4&gt;


&lt;p&gt;Se servir d'un widget comme zone de rendu cible pour SDL est très simple: il suffit d'une variable d'environnement. Cette variable est &lt;code&gt;SDL_WINDOWID&lt;/code&gt; et peut être de 2 formats:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;un entier, tel quel&lt;/li&gt;
&lt;li&gt;une valeur hexadécimale, préfixé par '0x'&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Une variable valide est un handle de fenêtre (dont le format peut varier en fonction de l'environnement utilisé). Ce handle s'obtient par la méthode &lt;code&gt;&lt;a href=&quot;http://doc.trolltech.com/4.2/qwidget.html#winId&quot; hreflang=&quot;en&quot;&gt;QWidget::winId()&lt;/a&gt;&lt;/code&gt;, qui est une méthode publique.&lt;/p&gt;


&lt;p&gt;Une fois la zone de rendu définie par cette variable, on peut initialiser le moteur graphique de SDL.
Voici par exemple le code permettant de réaliser cette intégration&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;cpp&quot;&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;char&lt;/span&gt; windowid&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #0000dd;&quot;&gt;64&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#93;&lt;/span&gt;;
&lt;span style=&quot;color: #339900;&quot;&gt;#ifdef Q_WS_WIN&lt;/span&gt;
	&lt;span style=&quot;color: #0000dd;&quot;&gt;sprintf&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;windowid, &lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot;SDL_WINDOWID=0x%lx&amp;quot;&lt;/span&gt;, reinterpret_cast&amp;lt;qlonglong&amp;gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;winId&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
&lt;span style=&quot;color: #339900;&quot;&gt;#elif defined Q_WS_X11&lt;/span&gt;
	&lt;span style=&quot;color: #0000dd;&quot;&gt;sprintf&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;windowid, &lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot;SDL_WINDOWID=0x%lx&amp;quot;&lt;/span&gt;, winId&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
&lt;span style=&quot;color: #339900;&quot;&gt;#else&lt;/span&gt;
	qFatal&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot;Fatal: cast du winId() inconnu pour votre plate-forme; toute information est la bienvenue!&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
&lt;span style=&quot;color: #339900;&quot;&gt;#endif&lt;/span&gt;
SDL_putenv&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;windowid&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
&lt;span style=&quot;color: #ff0000;&quot;&gt;// Initialisation du système vidéo de SDL&lt;/span&gt;
SDL_Init&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;SDL_INIT_VIDEO&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
screen = SDL_SetVideoMode&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;width&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;, height&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;, &lt;span style=&quot;color: #0000dd;&quot;&gt;32&lt;/span&gt;, SDL_SWSURFACE&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;/pre&gt;


&lt;blockquote&gt;&lt;p&gt;&lt;strong&gt;Attention&lt;/strong&gt;&amp;nbsp;: ne le faîtes pas l'initialisation du système vidéo de SDL avant que la création réelle de votre widget (le moment le plus sûr est lors du premier showEvent), sinon une seconde fenêtre sera créée par et pour SDL.&lt;/p&gt;&lt;/blockquote&gt;


&lt;h4&gt;Configuration du widget de rendu&lt;/h4&gt;


&lt;p&gt;Le dessin direct par SDL sur un widget Qt implique une petite configuration des attributs de dessin du dit widget:&lt;/p&gt;
&lt;pre class=&quot;cpp&quot;&gt;setAttribute&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;Qt::&lt;span style=&quot;color: #00eeff;&quot;&gt;WA_PaintOnScreen&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
setAttribute&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;Qt::&lt;span style=&quot;color: #00eeff;&quot;&gt;WA_NoSystemBackground&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;/pre&gt;


&lt;p&gt;A faire lors de l'utilisation de SDL, sinon, vous aurez une bouillie de pixels &quot;inspirée&quot; par le fond de l'écran à cet emplacement ;)&lt;/p&gt;


&lt;h4&gt;Conflit de main&lt;/h4&gt;


&lt;p&gt;Il y a par contre un conflit entre SDL et Qt au niveau de la fonction &lt;code&gt;main&lt;/code&gt;. Lorsque &lt;code&gt;main&lt;/code&gt; n'est pas le point d'entrée d'un programme (ce qui est le cas sur win32 par exemple), Qt appelle main à partir de son implémentation de &lt;code&gt;WinMain&lt;/code&gt;. SDL quant à lui fait un define (code extrait de &lt;code&gt;SDL_main.h&lt;/code&gt;)&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;cpp&quot;&gt;&lt;span style=&quot;color: #339900;&quot;&gt;#define main SDL_main&lt;/span&gt;
&lt;span style=&quot;color: #ff0000; font-style: italic;&quot;&gt;/* The prototype for the application's main() function */&lt;/span&gt;
&lt;span style=&quot;color: #0000ff;&quot;&gt;extern&lt;/span&gt; C_LINKAGE &lt;span style=&quot;color: #0000ff;&quot;&gt;int&lt;/span&gt; SDL_main&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;int&lt;/span&gt; argc, &lt;span style=&quot;color: #0000ff;&quot;&gt;char&lt;/span&gt; *argv&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;/pre&gt;


&lt;p&gt;Pour supprimer ce problème, ils vous faut annuler la définition de SDL, juste après l'inclusion de &lt;code&gt;SDL.h&lt;/code&gt;&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;cpp&quot;&gt;&lt;span style=&quot;color: #339900;&quot;&gt;#include &amp;quot;SDL.h&amp;quot;&lt;/span&gt;
&lt;span style=&quot;color: #339900;&quot;&gt;#undef main&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Une fois ceci fait, vous pouvez utiliser sereinement le système vidéo de SDL au sein de votre application Qt :)&lt;/p&gt;



&lt;h3&gt;Modification du fichier projet&lt;/h3&gt;


&lt;p&gt;Comme toute librairie, son utilisation avec votre programme doit être expressément signalée sous peine d'erreurs de compilation et/ou de liaison. Les informations à ajouter dans le fichier projet sont&amp;nbsp;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;le chemin vers les en-têtes SDL (ex: &lt;code&gt;INCLUDEPATH += /usr/local/include/&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;la librairie avec laquelle lier (et éventuellement son chemin) (ex: &lt;code&gt;LIBS += -L/usr/local/lib/ -lSDL&lt;/code&gt;)&lt;/li&gt;
&lt;/ul&gt;


&lt;h3&gt;Exemple complet&lt;/h3&gt;


&lt;p&gt;Vous trouverez associé à ce tutoriel &lt;a href=&quot;http://doc.qtfr.org/public/2006/qt_sdl.tar.gz&quot;&gt;un exemple&lt;/a&gt; illustrant l'utilisation de la SDL pour un starfield - qui rappellera des souvenirs aux (ex-)possesseurs de vieilles machines et qui ont codé avant l’arrivée du S-VGA (définit comme étant haute-résolution à l’époque) ;-)&lt;/p&gt;


&lt;p&gt;J'ai repris ici les points principaux de la classe&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;cpp&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#91;&lt;/span&gt;...&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#93;&lt;/span&gt;
&amp;nbsp;
&lt;span style=&quot;color: #339900;&quot;&gt;#ifdef Q_WS_WIN&lt;/span&gt;
&lt;span style=&quot;color: #339900;&quot;&gt;#include &amp;lt;SDL.h&amp;gt;&lt;/span&gt;
&lt;span style=&quot;color: #339900;&quot;&gt;#elif defined Q_WS_X11&lt;/span&gt;
&lt;span style=&quot;color: #339900;&quot;&gt;#include &amp;lt;SDL/SDL.h&amp;gt;&lt;/span&gt;
&lt;span style=&quot;color: #339900;&quot;&gt;#endif&lt;/span&gt;
&amp;nbsp;
&lt;span style=&quot;color: #ff0000; font-style: italic;&quot;&gt;/* PIEGE: main est redéfini par SDL.h comme SDL_Main.
                On retire donc la définition puisque Qt le gère
*/&lt;/span&gt;
&lt;span style=&quot;color: #339900;&quot;&gt;#undef main&lt;/span&gt;
&amp;nbsp;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#91;&lt;/span&gt;...&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#93;&lt;/span&gt;
&amp;nbsp;
&lt;span style=&quot;color: #0000ff;&quot;&gt;class&lt;/span&gt; SDLWidget : &lt;span style=&quot;color: #0000ff;&quot;&gt;public&lt;/span&gt; QWidget
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
    Q_OBJECT
&amp;nbsp;
&lt;span style=&quot;color: #0000ff;&quot;&gt;public&lt;/span&gt;:
    SDLWidget&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
    :refreshTimer&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000dd;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;, windowInitialized&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;false&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;, screen&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000dd;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;, StarNumbers&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000dd;&quot;&gt;100&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#91;&lt;/span&gt;...&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#93;&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
    &lt;span style=&quot;color: #0000ff;&quot;&gt;virtual&lt;/span&gt; ~SDLWidget&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
        SDL_Quit&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
&lt;span style=&quot;color: #0000ff;&quot;&gt;protected&lt;/span&gt;:
    &lt;span style=&quot;color: #0000ff;&quot;&gt;virtual&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;void&lt;/span&gt; showEvent&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;QShowEvent *e&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
        &lt;span style=&quot;color: #0000ff;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;!windowInitialized&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
            &lt;span style=&quot;color: #ff0000;&quot;&gt;// C'est ici qu'on dis à SDL d'utiliser notre widget&lt;/span&gt;
            &lt;span style=&quot;color: #0000ff;&quot;&gt;char&lt;/span&gt; windowid&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #0000dd;&quot;&gt;64&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#93;&lt;/span&gt;;
&lt;span style=&quot;color: #339900;&quot;&gt;#ifdef Q_WS_WIN&lt;/span&gt;
&amp;nbsp;
			&lt;span style=&quot;color: #0000dd;&quot;&gt;sprintf&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;windowid, &lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot;SDL_WINDOWID=0x%lx&amp;quot;&lt;/span&gt;, reinterpret_cast&amp;lt;qlonglong&amp;gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;winId&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
&lt;span style=&quot;color: #339900;&quot;&gt;#elif defined Q_WS_X11&lt;/span&gt;
			&lt;span style=&quot;color: #0000dd;&quot;&gt;sprintf&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;windowid, &lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot;SDL_WINDOWID=0x%lx&amp;quot;&lt;/span&gt;, winId&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
&lt;span style=&quot;color: #339900;&quot;&gt;#else&lt;/span&gt;
			qFatal&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot;Fatal: cast du winId() inconnu pour votre plate-forme; toute information est la bienvenue!&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
&lt;span style=&quot;color: #339900;&quot;&gt;#endif&lt;/span&gt;
            SDL_putenv&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;windowid&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
&amp;nbsp;
            &lt;span style=&quot;color: #ff0000;&quot;&gt;// Initialisation du système vidéo de SDL&lt;/span&gt;
            SDL_Init&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;SDL_INIT_VIDEO&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
            screen = SDL_SetVideoMode&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;width&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;, height&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;, &lt;span style=&quot;color: #0000dd;&quot;&gt;32&lt;/span&gt;, SDL_SWSURFACE&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
            windowInitialized = &lt;span style=&quot;color: #0000ff;&quot;&gt;true&lt;/span&gt;;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
&lt;span style=&quot;color: #0000ff;&quot;&gt;private&lt;/span&gt;:
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#91;&lt;/span&gt;...&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#93;&lt;/span&gt;
&amp;nbsp;
&lt;span style=&quot;color: #0000ff;&quot;&gt;private&lt;/span&gt;:
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#91;&lt;/span&gt;...&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#93;&lt;/span&gt;
&amp;nbsp;
&lt;span style=&quot;color: #0000ff;&quot;&gt;private&lt;/span&gt; slots:
    &lt;span style=&quot;color: #0000ff;&quot;&gt;void&lt;/span&gt; onRefresh&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
        &lt;span style=&quot;color: #0000ff;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;windowInitialized &amp;amp;&amp;amp; screen&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
            SDL_LockSurface&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;screen&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
                &lt;span style=&quot;color: #ff0000;&quot;&gt;// Nettoyage de l'écran&lt;/span&gt;
                SDL_FillRect&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;screen, &lt;span style=&quot;color: #0000ff;&quot;&gt;NULL&lt;/span&gt;, &lt;span style=&quot;color: #0000dd;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
                &lt;span style=&quot;color: #ff0000;&quot;&gt;// Dessin du starfield&lt;/span&gt;
                drawStarfield&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
            SDL_UnlockSurface&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;screen&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
&amp;nbsp;
            &lt;span style=&quot;color: #ff0000;&quot;&gt;// Rafraîchissement...&lt;/span&gt;
            SDL_UpdateRect&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;screen, &lt;span style=&quot;color: #0000dd;&quot;&gt;0&lt;/span&gt;, &lt;span style=&quot;color: #0000dd;&quot;&gt;0&lt;/span&gt;, &lt;span style=&quot;color: #0000dd;&quot;&gt;0&lt;/span&gt;, &lt;span style=&quot;color: #0000dd;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
&amp;nbsp;
            &lt;span style=&quot;color: #ff0000;&quot;&gt;// Et enfin, mise à jour des positions des étoiles&lt;/span&gt;
            updateStarfield&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
&lt;span style=&quot;color: #0000ff;&quot;&gt;private&lt;/span&gt;:
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#91;&lt;/span&gt;...&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#93;&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;;&lt;/pre&gt;


&lt;p&gt;N’oubliez pas d’ajouter les références d’inclusion et de bibliothèques de SDL au .pro, et laissez vous aller à un peu de nostalgie ;-)&lt;/p&gt;


&lt;h3&gt;Utilisation avancée&lt;/h3&gt;


&lt;p&gt;L'ensemble du code illustrant l'utilisation décrite ici est disponible sur &lt;a href=&quot;http://doc.qtfr.org/public/2006/sdl_adv.tar.gz&quot;&gt;la seconde pièce jointe&lt;/a&gt;.&lt;/p&gt;


&lt;p&gt;La méthode décrite précédemment est suffisante si vous n'avez besoin de SDL que dans un seul widget. Mais si vous voulez utiliser SDL comme système d'affichage pour plusieurs widgets, alors il faut changer de stratégie. En effet, SDL ayant pris le parti d'utiliser une seule et unique variable d'environnement pointant vers un et un seul identifiant de fenêtre, il va nous falloir utiliser ce système différemment.&lt;/p&gt;


&lt;p&gt;Nous allons donc devoir créer un widget invisible servant à initialiser le système SDL. (Vous trouverez une classe remplissant cette fonctionnalité dans les fichiers tools.h et tools.cpp (classe &lt;code&gt;SDLContext&lt;/code&gt;) fournis avec l'archive.) Le dessin se fera alors sur diverses surfaces SDL (au moins 1 par widget où vous comptez l'utiliser en fait).&lt;/p&gt;


&lt;p&gt;Il nous font donc aussi des fonctions de conversion entre &lt;code&gt;QImage&lt;/code&gt; et &lt;code&gt;SDL_Surface&lt;/code&gt;, ainsi qu'une fonction de création de &lt;code&gt;SDL_Surface&lt;/code&gt;. Cette dernière est nécessaire afin de paramétrer les surfaces SDL de façon à ce que leur format soit compatible à 100% avec les formats proposés par &lt;code&gt;QImage&lt;/code&gt;. Dans l'exemple, ces fonctions ne couvrent pas tout les cas nécessaires, il ne tient qu'à vous de les compléter selon vos besoins:&lt;/p&gt;
&lt;pre class=&quot;cpp&quot;&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;// Création d'une surface SDL rapidement convertible en QImage&lt;/span&gt;
SDL_Surface* createQImageCompliantSurface&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;Uint32 flags, &lt;span style=&quot;color: #0000ff;&quot;&gt;int&lt;/span&gt; width, &lt;span style=&quot;color: #0000ff;&quot;&gt;int&lt;/span&gt; height&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
	&lt;span style=&quot;color: #0000ff;&quot;&gt;static&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;const&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;int&lt;/span&gt; Rmask = 0x00FF0000;
	&lt;span style=&quot;color: #0000ff;&quot;&gt;static&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;const&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;int&lt;/span&gt; Gmask = 0x0000FF00;
	&lt;span style=&quot;color: #0000ff;&quot;&gt;static&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;const&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;int&lt;/span&gt; Bmask = 0x000000FF;
	&lt;span style=&quot;color: #0000ff;&quot;&gt;static&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;const&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;int&lt;/span&gt; Amask = 0xFF000000;
&amp;nbsp;
	&lt;span style=&quot;color: #0000ff;&quot;&gt;return&lt;/span&gt; SDL_CreateRGBSurface&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;flags, width, height, &lt;span style=&quot;color: #0000dd;&quot;&gt;32&lt;/span&gt;, Rmask, Gmask, Bmask, Amask&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
&lt;span style=&quot;color: #ff0000; font-style: italic;&quot;&gt;/* Fonctions de conversion entre SDL_Surface et QImage
   SDLSurfaceToQImage **DOIT** recevoir une surface
   construite avec createQImageCompliantSurface
*/&lt;/span&gt;
QImage SDLSurfaceToQImage&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;SDL_Surface *s&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
	SDL_LockSurface&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;s&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
		QImage im&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;static_cast&amp;lt;uchar*&amp;gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;s-&amp;gt;pixels&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;, s-&amp;gt;w, s-&amp;gt;h, QImage::&lt;span style=&quot;color: #00eeff;&quot;&gt;Format_RGB32&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
        SDL_UnlockSurface&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;s&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
&amp;nbsp;
	&lt;span style=&quot;color: #0000ff;&quot;&gt;return&lt;/span&gt; im;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;2 améliorations conseillées:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;il est intéressant de définir notre propre type encapsulant ceci afin de réduire à 0 le risque de passer une mauvaise surface.&lt;/li&gt;
&lt;li&gt;on peut ajouter une méthode SDLSurfaceToQImage prenant en paramètre une référence vers un QImage afin de modifier les données d'un QImage précédemment créé. Dans les scènes requierant un affichage rapide, cela peut apporter une différence&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;br /&gt;
Nous avons donc un système SDL fonctionnel pour l'appli ainsi que la possibilité d'avoir des surfaces dont la transformation en QImage est extrêmement rapide (puisqu'il s'agit de la copie brute des octets formant la surface). A la différence de la première partie du tutoriel, nous ne dessinons plus sur une surface affichée à l'écran (que nous utilisions ou non le double buffering ne change rien). Il va donc nous falloir surcharger &lt;a href=&quot;http://doc.trolltech.com/4.4/qwidget.html#paintEvent&quot;&gt;paintEvent&lt;/a&gt; pour gérer l'affichage. La mise à jour de notre QImage se fera à chaque mise à jour de la surface. Inutile de le faire dans le paintEvent puisque certains de ces événements seront générés par le système sans qu'il y ait obligatoirement eu de modifications de la surface, par exemple le fait que le widget soit minimisé puis restauré/maximisé.&lt;/p&gt;

&lt;pre class=&quot;cpp&quot;&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;class&lt;/span&gt; Widget : &lt;span style=&quot;color: #0000ff;&quot;&gt;public&lt;/span&gt; QWidget
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
&lt;span style=&quot;color: #0000ff;&quot;&gt;protected&lt;/span&gt;:
   &lt;span style=&quot;color: #0000ff;&quot;&gt;virtual&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;void&lt;/span&gt; paintEvent&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;QPaintEvent *e&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
   &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
      QPainter p&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000dd;&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
      p.&lt;span style=&quot;color: #00eeff;&quot;&gt;drawImage&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;displayBuffer&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
   &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
   &lt;span style=&quot;color: #0000ff;&quot;&gt;void&lt;/span&gt; modificationSurfaceSDL&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
   &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
      &lt;span style=&quot;color: #ff0000; font-style: italic;&quot;&gt;/* on modifie la surface renderer par diverses opérations de dessin */&lt;/span&gt;
      displayBuffer = SDLSurfaceToQImage&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;renderer&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
      update&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;; &lt;span style=&quot;color: #ff0000;&quot;&gt;// on demande par la même occasion un rafraichissement du widget&lt;/span&gt;
   &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
&lt;span style=&quot;color: #0000ff;&quot;&gt;private&lt;/span&gt;:
   SDL_Surface *renderer;
   QImage displayBuffer;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;;&lt;/pre&gt;


&lt;p&gt;Voici le screenshot obligatoire présentant l'exemple en cours d'exécution:
&lt;a href=&quot;http://doc.qtfr.org/public/2006/sdl_adv.png&quot;&gt;&lt;img src=&quot;http://doc.qtfr.org/public/2006/.sdl_adv_m.jpg&quot; alt=&quot;Illustration SDL multi-widget&quot; style=&quot;display:block; margin:0 auto;&quot; /&gt;&lt;/a&gt;&lt;/p&gt;</description>
    
          <enclosure url="http://doc.qtfr.org/public/2006/sdl_qt.tar.gz"
      length="2169" type="application/x-gzip" />
          <enclosure url="http://doc.qtfr.org/public/2006/sdl_adv.tar.gz"
      length="3667" type="application/x-gzip" />
    
    
      </item>
    
  <item>
    <title>C++ GUI Programming with Qt 4</title>
    <link>http://doc.qtfr.org/post/2007/02/20/C-GUI-Programming-with-Qt-4</link>
    <guid isPermaLink="false">urn:md5:b9d78bb6ba29b6443d08fe4f46398204</guid>
    <pubDate>Tue, 20 Feb 2007 09:38:00 +0100</pubDate>
    <dc:creator>Nicolas</dc:creator>
        <category>Livres</category>
        <category>livre</category><category>version_Qt4</category>    
    <description>&lt;p&gt;Livre officiel de Trolltech pour la programmation Qt (version 4.1), ce livre est en fait une mise à jour de &lt;strong&gt;C++ GUI programming with Qt 3&lt;/strong&gt;. Il aborde tous les aspects de la bibliothèque&amp;nbsp;: organisation des widgets, évènements, programmation 2D et 3D...&lt;/p&gt;    &lt;p&gt;&lt;a href=&quot;http://www.phptr.com/bookstore/product.asp?isbn=0131872494&amp;amp;rl=1&quot;&gt;&lt;img src=&quot;http://doc.qtfr.org/public/livres/programming-qt4.jpg&quot; alt=&quot;programming-qt4.jpg&quot; style=&quot;float:right; margin: 0 0 1em 1em;&quot; /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;Informations&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;em&gt;Auteurs&lt;/em&gt;&amp;nbsp;: Jasmin Blanchette et Mark Summerfield&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Editeur&lt;/em&gt;&amp;nbsp;: &lt;a href=&quot;http://vig.prenhall.com/&quot; hreflang=&quot;en&quot;&gt;Prentice Hall PTR&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Collection&lt;/em&gt;&amp;nbsp;: &lt;a href=&quot;http://www.phptr.com/bookstore/product.asp?isbn=0131872494&amp;amp;rl=1&quot; hreflang=&quot;en&quot;&gt;Bruce Perens' Open Source Series&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Langue&lt;/em&gt;&amp;nbsp;: anglais&lt;/li&gt;
&lt;li&gt;&lt;em&gt;ISBN&lt;/em&gt;&amp;nbsp;: 0131872494&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Pages&lt;/em&gt;&amp;nbsp;: 560&lt;/li&gt;
&lt;/ul&gt;


&lt;h3&gt;Résumé&lt;/h3&gt;


&lt;p&gt;Le second &lt;strong&gt;livre officiel de Trolltech&lt;/strong&gt;, traitant de la programmation Qt4. Ce livre est une mise à jour de &lt;em&gt;C++ GUI Programming with Qt3&lt;/em&gt;.&lt;/p&gt;


&lt;p&gt;Ce livre couvre tous les aspects de la programmation Qt, avec une première partie offrant une approche simple pour le débutant, en détaillant pas à pas la création d'une application complète. La seconde partie détaille les différents aspects de la bibliothèque&amp;nbsp;: organisation des widgets, évènements, programmation 2D et 3D... Enfin, la dernière partie aborde des aspects plus complexes&amp;nbsp;: internationalisation, multi-threading.&lt;/p&gt;


&lt;p&gt;Le CD comporte les versions GPL de Qt 4.1.1 sous Windows/Linux/Mac OSX.&lt;/p&gt;


&lt;p&gt;Un chapitre du livre est actuellement en &lt;strong&gt;libre téléchargement en PDF&lt;/strong&gt; sur le site de &lt;a href=&quot;http://www.phptr.com/bookstore/product.asp?isbn=0131872494&amp;amp;rl=1#info3&quot; hreflang=&quot;en&quot;&gt;Prentice Hall&lt;/a&gt;.&lt;/p&gt;



&lt;h3&gt;Table des matières&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Part I: Basic Qt
&lt;ul&gt;
&lt;li&gt;Getting Started&lt;/li&gt;
&lt;li&gt;Creating Dialogs&lt;/li&gt;
&lt;li&gt;Creating Main Windows&lt;/li&gt;
&lt;li&gt;Implementing Application Functionality&lt;/li&gt;
&lt;li&gt;Creating Custom Widgets&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;Part II: Intermediate Qt
&lt;ul&gt;
&lt;li&gt;Layout Management&lt;/li&gt;
&lt;li&gt;Event Processing&lt;/li&gt;
&lt;li&gt;2D and 3D Graphics&lt;/li&gt;
&lt;li&gt;Drag and Drop&lt;/li&gt;
&lt;li&gt;Item View Classes&lt;/li&gt;
&lt;li&gt;Container Classes&lt;/li&gt;
&lt;li&gt;Input/Output&lt;/li&gt;
&lt;li&gt;Databases&lt;/li&gt;
&lt;li&gt;Networking&lt;/li&gt;
&lt;li&gt;XML&lt;/li&gt;
&lt;li&gt;Providing Online Help&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;Part III: Advanced Qt
&lt;ul&gt;
&lt;li&gt;Internationalization&lt;/li&gt;
&lt;li&gt;Multithreading&lt;/li&gt;
&lt;li&gt;Creating Plugins&lt;/li&gt;
&lt;li&gt;Platform-Specific Features&lt;/li&gt;
&lt;li&gt;Embedded Programming&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;Appendices
&lt;ul&gt;
&lt;li&gt;Installing Qt&lt;/li&gt;
&lt;li&gt;Introduction to C++ for Java and C# Programmers&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;/ul&gt;</description>
    
    
    
      </item>
    
  <item>
    <title>Etendre le type QVariant</title>
    <link>http://doc.qtfr.org/post/2007/02/19/Etendre-le-type-QVariant</link>
    <guid isPermaLink="false">urn:md5:060bddd9917af28f0dd0b18fff8b6bae</guid>
    <pubDate>Mon, 19 Feb 2007 22:53:00 +0100</pubDate>
    <dc:creator>IrmatDen</dc:creator>
        <category>Tutoriels</category>
        <category>class_QPointer</category><category>class_QVariant</category><category>type</category><category>version_Qt4</category>    
    <description>&lt;ul&gt;
&lt;li&gt;Comment étendre QVariant avec ses propres objets&amp;nbsp;?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Ce tutoriel va nous montrer comment étendre QVariant avec ses propres types.&lt;/p&gt;


&lt;p&gt;&lt;strong&gt;Version&lt;/strong&gt;&amp;nbsp;: Qt4 &lt;br /&gt;
&lt;strong&gt;Auteur&lt;/strong&gt;&amp;nbsp;: Denys Bulant (&lt;a href=&quot;http://forum.qtfr.org/profile.php?id=291&quot;&gt;IrmatDen&lt;/a&gt;)&lt;/p&gt;    &lt;h3&gt;Introduction&lt;/h3&gt;


&lt;p&gt;&lt;code&gt;QVariant&lt;/code&gt; est un type très puissant permettant de stocker n’importe quel type de variable sous une forme abstraite. Depuis Qt4, il est possible d’y rajouter ses propres types, ainsi que celui de librairies tierces. Il y a 2 restrictions&amp;nbsp;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Connaître le nom du type (facile ;-) )&lt;/li&gt;
&lt;li&gt;Dans le cas d’une classe, elle doit répondre aux contraintes suivantes&amp;nbsp;:
&lt;ul&gt;
&lt;li&gt;avoir un constructeur par défaut public (ne prenant aucun argument, ou tous les arguments ayant une valeur par défaut),&lt;/li&gt;
&lt;li&gt;avoir un constructeur par copie public (c-a-d &lt;code&gt;MaClasse(const MaClasse&amp;amp;)&lt;/code&gt; ),&lt;/li&gt;
&lt;li&gt;avoir un destructeur public.&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Il suffit d’ajouter la macro &lt;code&gt;&lt;a href=&quot;http://doc.trolltech.com/4.2/qmetatype.html#Q_DECLARE_METATYPE&quot; hreflang=&quot;en&quot;&gt;Q_DECLARE_METATYPE(type)&lt;/a&gt;&lt;/code&gt;, après avoir inclus &lt;code&gt;QVariant&lt;/code&gt;, et après la déclaration du type. Si le type à gérer est déclaré dans un en-tête que vous ne pouvez/voulez pas toucher (celui d’une bibliothèque tierce par exemple), il suffit de la saisir quelque part après l’inclusion dudit en-tête.&lt;/p&gt;



&lt;h3&gt;Exemple&lt;/h3&gt;


&lt;p&gt;Voici un exemple illustrant cette fonctionnalité. Imaginons que nous voulions nous servir de &lt;code&gt;QVariant&lt;/code&gt; pour transmettre les données d’un type &lt;code&gt;Vector3&lt;/code&gt; défini dans une lib tierce (bien que les sources soient fournis ici pour éviter les multiples projets...).&lt;/p&gt;



&lt;h4&gt;Vector3&lt;/h4&gt;


&lt;p&gt;Ce type est défini dans le fichier suivant vector3.h.&lt;/p&gt;

&lt;pre class=&quot;cpp&quot;&gt;&lt;span style=&quot;color: #339900;&quot;&gt;#ifndef VECTOR3_H&lt;/span&gt;
&lt;span style=&quot;color: #339900;&quot;&gt;#define VECTOR3_H&lt;/span&gt;
&lt;span style=&quot;color: #0000ff;&quot;&gt;class&lt;/span&gt; Vector3
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
&lt;span style=&quot;color: #0000ff;&quot;&gt;public&lt;/span&gt;:
    Vector3&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; : m_x&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000dd;&quot;&gt;0.0&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;, m_y&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000dd;&quot;&gt;0.0&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;, m_z&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000dd;&quot;&gt;0.0&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
    Vector3&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;float&lt;/span&gt; x, &lt;span style=&quot;color: #0000ff;&quot;&gt;float&lt;/span&gt; y, &lt;span style=&quot;color: #0000ff;&quot;&gt;float&lt;/span&gt; z&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; : m_x&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;x&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;, m_y&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;y&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;, m_z&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;z&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
    Vector3&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;const&lt;/span&gt; Vector3 &amp;amp;v&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; : m_x&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;v.&lt;span style=&quot;color: #00eeff;&quot;&gt;m_x&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;, m_y&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;v.&lt;span style=&quot;color: #00eeff;&quot;&gt;m_y&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;, m_z&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;v.&lt;span style=&quot;color: #00eeff;&quot;&gt;m_z&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
    ~Vector3&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
    &lt;span style=&quot;color: #0000ff;&quot;&gt;float&lt;/span&gt; getX&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;const&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;return&lt;/span&gt; m_x; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
    &lt;span style=&quot;color: #0000ff;&quot;&gt;float&lt;/span&gt; getY&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;const&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;return&lt;/span&gt; m_y; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
    &lt;span style=&quot;color: #0000ff;&quot;&gt;float&lt;/span&gt; getZ&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;const&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;return&lt;/span&gt; m_z; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
    &lt;span style=&quot;color: #0000ff;&quot;&gt;void&lt;/span&gt; setX&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;float&lt;/span&gt; x&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt; m_x = x; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
    &lt;span style=&quot;color: #0000ff;&quot;&gt;void&lt;/span&gt; setY&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;float&lt;/span&gt; y&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt; m_y = y; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
    &lt;span style=&quot;color: #0000ff;&quot;&gt;void&lt;/span&gt; setZ&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;float&lt;/span&gt; z&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt; m_z = z; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
&lt;span style=&quot;color: #0000ff;&quot;&gt;private&lt;/span&gt;:
    &lt;span style=&quot;color: #0000ff;&quot;&gt;float&lt;/span&gt; m_x, m_y, m_z;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;;
&lt;span style=&quot;color: #ff0000;&quot;&gt;// S'il s'agissait de votre propre classe et que vous vouliez la coupler pour de bon à Qt,&lt;/span&gt;
&lt;span style=&quot;color: #ff0000;&quot;&gt;// vous voudriez très probablement ajouter ces 2 lignes:&lt;/span&gt;
&lt;span style=&quot;color: #ff0000;&quot;&gt;// #include &amp;lt;QVariant&amp;gt;&lt;/span&gt;
&lt;span style=&quot;color: #ff0000;&quot;&gt;// Q_DECLARE_METATYPE(Vector3);&lt;/span&gt;
&lt;span style=&quot;color: #339900;&quot;&gt;#endif&lt;/span&gt;&lt;/pre&gt;


&lt;h4&gt;Utilisation de Vector3 avec QVariant&lt;/h4&gt;


&lt;p&gt;Pas grand chose à expliquer ci-dessous, la doc citée en début de document illustre la conversion vers et à partir d’un QVariant avec type personnalisé.&lt;/p&gt;

&lt;pre class=&quot;cpp&quot;&gt;&lt;span style=&quot;color: #339900;&quot;&gt;#include &amp;lt;iostream&amp;gt;&lt;/span&gt;
&lt;span style=&quot;color: #339900;&quot;&gt;#include &amp;lt;string&amp;gt;&lt;/span&gt;
&lt;span style=&quot;color: #339900;&quot;&gt;#include &amp;lt;QVariant&amp;gt;&lt;/span&gt;
&lt;span style=&quot;color: #339900;&quot;&gt;#include &amp;quot;vector3.h&amp;quot;&lt;/span&gt;
&lt;span style=&quot;color: #ff0000;&quot;&gt;// Nous enregistrons le type Vector3 pour son utilisation avec QVariant&lt;/span&gt;
&lt;span style=&quot;color: #ff0000;&quot;&gt;// seulement nécessaire si ce n'est pas déjà dans le fichier d'en-tête&lt;/span&gt;
Q_DECLARE_METATYPE&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;Vector3&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
&lt;span style=&quot;color: #0000ff;&quot;&gt;using&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;namespace&lt;/span&gt; std;
&lt;span style=&quot;color: #0000ff;&quot;&gt;inline&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;void&lt;/span&gt; displayVector3&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;const&lt;/span&gt; string &amp;amp;name, &lt;span style=&quot;color: #0000ff;&quot;&gt;const&lt;/span&gt; Vector3 &amp;amp;v&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span style=&quot;color: #0000dd;&quot;&gt;cout&lt;/span&gt; &amp;lt;&amp;lt; name &amp;lt;&amp;lt; &lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot;={&amp;quot;&lt;/span&gt;
        &amp;lt;&amp;lt; v.&lt;span style=&quot;color: #00eeff;&quot;&gt;getX&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; &amp;lt;&amp;lt; &lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot;,&amp;quot;&lt;/span&gt;
        &amp;lt;&amp;lt; v.&lt;span style=&quot;color: #00eeff;&quot;&gt;getY&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; &amp;lt;&amp;lt; &lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot;,&amp;quot;&lt;/span&gt;
        &amp;lt;&amp;lt; v.&lt;span style=&quot;color: #00eeff;&quot;&gt;getZ&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; &amp;lt;&amp;lt; &lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot;}&amp;quot;&lt;/span&gt; &amp;lt;&amp;lt; endl;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span style=&quot;color: #0000ff;&quot;&gt;int&lt;/span&gt; main&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;int&lt;/span&gt; argc, &lt;span style=&quot;color: #0000ff;&quot;&gt;char&lt;/span&gt; **argv&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
    Vector3 v1&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000dd;&quot;&gt;1.0&lt;/span&gt;, &lt;span style=&quot;color: #0000dd;&quot;&gt;1.0&lt;/span&gt;, &lt;span style=&quot;color: #0000dd;&quot;&gt;0.5&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
    displayVector3&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;string&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot;v1&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;, v1&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
    QVariant var;
    var.&lt;span style=&quot;color: #00eeff;&quot;&gt;setValue&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;v1&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;; &lt;span style=&quot;color: #ff0000;&quot;&gt;// var contient donc maintenant v1(1.0, 1.0, 0.5);&lt;/span&gt;
    Vector3 v2&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000dd;&quot;&gt;5.0&lt;/span&gt;, &lt;span style=&quot;color: #0000dd;&quot;&gt;0.75&lt;/span&gt;, &lt;span style=&quot;color: #0000dd;&quot;&gt;0.25&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
    displayVector3&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;string&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot;v2a&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;, v2&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
    v2 = var.&lt;span style=&quot;color: #00eeff;&quot;&gt;value&lt;/span&gt;&amp;lt;Vector3&amp;gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;; &lt;span style=&quot;color: #ff0000;&quot;&gt;// récupération dans v2 du Vector3 contenu dans var (ie v1)&lt;/span&gt;
    displayVector3&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;string&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot;v2b&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;, v2&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
    &lt;span style=&quot;color: #0000dd;&quot;&gt;cin&lt;/span&gt;.&lt;span style=&quot;color: #00eeff;&quot;&gt;get&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
    &lt;span style=&quot;color: #0000ff;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #0000dd;&quot;&gt;0&lt;/span&gt;;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;



&lt;h4&gt;Centralisons un peu&lt;/h4&gt;


&lt;p&gt;Voilà une première façon de faire. La récupération du &lt;code&gt;Vector3&lt;/code&gt; contenu dans le &lt;code&gt;QVariant&lt;/code&gt; se fait à l’aide d’une fonction template. Pour rendre les choses un peu plus lisible, et/ou si vous prévoyez de gérer un certain nombre de classes de cette façon, on peut tout simplement mettre ces macros à part, et regrouper les méthodes de conversion QVariant vers type personnalisé avec.&lt;/p&gt;


&lt;p&gt;En voici un exemple&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;cpp&quot;&gt;&lt;span style=&quot;color: #339900;&quot;&gt;#ifndef DECL_METATYPE_H&lt;/span&gt;
&lt;span style=&quot;color: #339900;&quot;&gt;#define DECL_METATYPE_H&lt;/span&gt;
&lt;span style=&quot;color: #ff0000;&quot;&gt;// Doit être inclus pour la macro Q_DECLARE_METATYPE et la définition de la classe Helper&lt;/span&gt;
&lt;span style=&quot;color: #339900;&quot;&gt;#include &amp;lt;QVariant&amp;gt;&lt;/span&gt;
&lt;span style=&quot;color: #ff0000;&quot;&gt;// Pour que Vector3 soit un type connu...&lt;/span&gt;
&lt;span style=&quot;color: #339900;&quot;&gt;#include &amp;quot;vector3.h&amp;quot;&lt;/span&gt;
&lt;span style=&quot;color: #ff0000;&quot;&gt;// Nous enregistrons le type Vector3 pour son utilisation avec QVariant&lt;/span&gt;
Q_DECLARE_METATYPE&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;Vector3&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
&lt;span style=&quot;color: #ff0000;&quot;&gt;// Namespace ajoutant des fonctions de conversion à partir de QVariant&lt;/span&gt;
&lt;span style=&quot;color: #0000ff;&quot;&gt;namespace&lt;/span&gt; QVariantHelper
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span style=&quot;color: #0000ff;&quot;&gt;inline&lt;/span&gt; Vector3 ToVector3&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;QVariant v&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
        &lt;span style=&quot;color: #0000ff;&quot;&gt;return&lt;/span&gt; v.&lt;span style=&quot;color: #00eeff;&quot;&gt;value&lt;/span&gt;&amp;lt;Vector3&amp;gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;;
&lt;span style=&quot;color: #339900;&quot;&gt;#endif&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;La seule modification à apporter au main serait la suivante&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;cpp&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#91;&lt;/span&gt;...&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#93;&lt;/span&gt;
    Vector3 v2&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000dd;&quot;&gt;5.0&lt;/span&gt;, &lt;span style=&quot;color: #0000dd;&quot;&gt;0.75&lt;/span&gt;, &lt;span style=&quot;color: #0000dd;&quot;&gt;0.25&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
    displayVector3&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;string&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot;v2a&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;, v2&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
    &lt;span style=&quot;color: #ff0000;&quot;&gt;// remplace l'utilisation d'un template par quelque chose&lt;/span&gt;
    &lt;span style=&quot;color: #ff0000;&quot;&gt;// de plus significatif (à mes yeux... ;))&lt;/span&gt;
    v2 = QVariantHelper::&lt;span style=&quot;color: #00eeff;&quot;&gt;ToVector3&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;var&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
    displayVector3&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;string&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot;v2b&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;, v2&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#91;&lt;/span&gt;...&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;/pre&gt;



&lt;h4&gt;Et les pointeurs&amp;nbsp;?&lt;/h4&gt;


&lt;p&gt;Quid des pointeurs vers des types personnalisés?&lt;/p&gt;


&lt;p&gt;Eux aussi sont transformables en &lt;code&gt;QVariant&lt;/code&gt;. Il suffit de les déclarer comme type eux aussi. En voici un exemple&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;cpp&quot;&gt;&lt;span style=&quot;color: #339900;&quot;&gt;#ifndef DECL_METATYPE_H&lt;/span&gt;
&lt;span style=&quot;color: #339900;&quot;&gt;#define DECL_METATYPE_H&lt;/span&gt;
&lt;span style=&quot;color: #339900;&quot;&gt;#include &amp;lt;QVariant&amp;gt;&lt;/span&gt;
&lt;span style=&quot;color: #339900;&quot;&gt;#include &amp;quot;vector3.h&amp;quot;&lt;/span&gt;
&lt;span style=&quot;color: #ff0000;&quot;&gt;// Nous enregistrons le type Vector3 pour son utilisation avec QVariant&lt;/span&gt;
Q_DECLARE_METATYPE&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;Vector3&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
&lt;span style=&quot;color: #ff0000;&quot;&gt;// ... ainsi que le type pointeur vers Vector3&lt;/span&gt;
Q_DECLARE_METATYPE&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;Vector3*&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
&lt;span style=&quot;color: #ff0000;&quot;&gt;// Namespace ajoutant des fonctions de conversion à partir de QVariant&lt;/span&gt;
&lt;span style=&quot;color: #0000ff;&quot;&gt;namespace&lt;/span&gt; QVariantHelper
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span style=&quot;color: #ff0000;&quot;&gt;// renvoit le Vector3 contenu dans v, ou le Vector3 par défaut&lt;/span&gt;
    &lt;span style=&quot;color: #ff0000;&quot;&gt;// si la conversion n'est pas faisable&lt;/span&gt;
    &lt;span style=&quot;color: #0000ff;&quot;&gt;inline&lt;/span&gt; Vector3 ToVector3&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;QVariant v&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
        &lt;span style=&quot;color: #0000ff;&quot;&gt;return&lt;/span&gt; v.&lt;span style=&quot;color: #00eeff;&quot;&gt;value&lt;/span&gt;&amp;lt;Vector3&amp;gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
    &lt;span style=&quot;color: #ff0000;&quot;&gt;// renvoit le Vector3* contenu dans v, ou 0 si la conversion n'est pas faisable&lt;/span&gt;
    &lt;span style=&quot;color: #0000ff;&quot;&gt;inline&lt;/span&gt; Vector3* ToVector3Ptr&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;QVariant v&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
        &lt;span style=&quot;color: #0000ff;&quot;&gt;return&lt;/span&gt; v.&lt;span style=&quot;color: #00eeff;&quot;&gt;value&lt;/span&gt;&amp;lt;Vector3*&amp;gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;;
&lt;span style=&quot;color: #339900;&quot;&gt;#endif&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Et voici l’assignation d’un pointeur à &lt;code&gt;QVariant&lt;/code&gt; et son extraction&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;cpp&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#91;&lt;/span&gt;...&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#93;&lt;/span&gt;
    QVariant varVec3;
    varVec3.&lt;span style=&quot;color: #00eeff;&quot;&gt;setValue&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;v1&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
    QVariant varVec3Ptr = QVariant::&lt;span style=&quot;color: #00eeff;&quot;&gt;fromValue&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&amp;amp;v1&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;; &lt;span style=&quot;color: #ff0000;&quot;&gt;// Notation générique alternative pour l'assignation d'une valeur à un QVariant&lt;/span&gt;
    Vector3 v2&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000dd;&quot;&gt;5.0&lt;/span&gt;, &lt;span style=&quot;color: #0000dd;&quot;&gt;0.75&lt;/span&gt;, &lt;span style=&quot;color: #0000dd;&quot;&gt;0.25&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
    displayVector3&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;string&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot;v2a&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;, v2&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
    v2 = QVariantHelper::&lt;span style=&quot;color: #00eeff;&quot;&gt;ToVector3&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;varVec3&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
    displayVector3&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;string&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot;v2b&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;, v2&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
    Vector3 *v3 = QVariantHelper::&lt;span style=&quot;color: #00eeff;&quot;&gt;ToVector3Ptr&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;varVec3Ptr&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
    &lt;span style=&quot;color: #ff0000;&quot;&gt;// TOUJOURS vérifier si v3 est valide avant utilisation !&lt;/span&gt;
    &lt;span style=&quot;color: #0000ff;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;v3&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
        displayVector3&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;string&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot;v3(ptr)&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;, *v3&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
    &lt;span style=&quot;color: #0000ff;&quot;&gt;else&lt;/span&gt;
        &lt;span style=&quot;color: #0000dd;&quot;&gt;cout&lt;/span&gt; &amp;lt;&amp;lt; &lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot;v3 is an invalid pointer to Vector3!&amp;quot;&lt;/span&gt; &amp;lt;&amp;lt; endl;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#91;&lt;/span&gt;...&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Et enfin, si votre type est une classe dérivant de &lt;code&gt;QObject&lt;/code&gt;, vous devez utiliser &lt;code&gt;QPointer&lt;/code&gt;&amp;nbsp;: en effet, &lt;code&gt;QObject&lt;/code&gt; n'a pas de constructeur par copie.&lt;/p&gt;


&lt;p&gt;Pour cela, il faut juste déclarer le metatype avec le &lt;code&gt;QPointer&lt;/code&gt; représentant votre classe (ie &lt;code&gt;Q_DECLARE_METATYPE(QPointer&amp;lt;MyObject&amp;gt;)&lt;/code&gt;) en plus des déclarations de &lt;code&gt;MyObject&lt;/code&gt; et &lt;code&gt;MyObject*&lt;/code&gt;.&lt;/p&gt;


&lt;blockquote&gt;&lt;p&gt;&lt;strong&gt;Attention&lt;/strong&gt;&amp;nbsp;: &lt;code&gt;QPointer&amp;lt;VotreClasse&amp;gt;&lt;/code&gt; et &lt;code&gt;VotreClasse*&lt;/code&gt; sont incompatibles&amp;nbsp;!&lt;/p&gt;&lt;/blockquote&gt;</description>
    
    
    
      </item>
    
  <item>
    <title>Création de plugin avec Qt</title>
    <link>http://doc.qtfr.org/post/2007/02/18/Creation-de-plugin-avec-Qt</link>
    <guid isPermaLink="false">urn:md5:4d399514496b47bcf3234ec8055de61f</guid>
    <pubDate>Sun, 18 Feb 2007 23:11:00 +0100</pubDate>
    <dc:creator>Nicolas</dc:creator>
        <category>Tutoriels</category>
        <category>class_QObject</category><category>class_QPluginLoader</category><category>plugin</category><category>version_Qt4</category>    
    <description>&lt;ul&gt;
&lt;li&gt;Comment créer des plugins avec Qt&amp;nbsp;? et de manière multi-plateforme&amp;nbsp;?&lt;/li&gt;
&lt;li&gt;Comment permettre à mes utilisateurs d'étendre eux-mêmes mon application&amp;nbsp;?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Ce tutoriel va nous détailler la création d'un système de plugins avec la bibliothèque Qt, et le chargement de ces plugins depuis notre application.&lt;/p&gt;


&lt;p&gt;&lt;strong&gt;Version&lt;/strong&gt;&amp;nbsp;: Qt4 (supérieur ou égal à Qt 4.1) &lt;br /&gt;
&lt;strong&gt;Auteur&lt;/strong&gt;&amp;nbsp;: Nicolas Arnaud-Cormos (&lt;a href=&quot;http://forum.qtfr.org/profile.php?id=7&quot;&gt;nikikko&lt;/a&gt;) &lt;br /&gt;
&lt;strong&gt;Test&lt;/strong&gt;&amp;nbsp;: Linux (Qt 4.1, 4.2)&lt;/p&gt;    &lt;h3&gt;Plugin, vous avez dit plugin&amp;nbsp;?&lt;/h3&gt;


&lt;h4&gt;Qu'est-ce que c'est&amp;nbsp;?&lt;/h4&gt;


&lt;p&gt;Je n'ai pas réussit à faire mieux que &lt;a href=&quot;http://fr.wikipedia.org/wiki/Plugin&quot; hreflang=&quot;fr&quot;&gt;Wikipedia&lt;/a&gt; pour la définition&amp;nbsp;:&lt;/p&gt;


&lt;blockquote&gt;&lt;p&gt;En informatique, un plugin ou plug-in, de l'anglais to plug in (brancher), parfois traduit en module externe, module enfichable, module d'extension, greffon ou plugiciel, est un logiciel tiers venant se greffer à un logiciel principal afin de lui apporter de nouvelles fonctionnalités. Le logiciel principal fixe un standard d'échange d'informations auquel ses modules se conforment. Le module n'est généralement pas conçu pour fonctionner seul mais avec un autre programme.&lt;/p&gt;&lt;/blockquote&gt;



&lt;h4&gt;Comment ça marche&amp;nbsp;?&lt;/h4&gt;


&lt;p&gt;C'est relativement simple (en théorie ;))&amp;nbsp;:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Le logiciel principal défini une API standard&amp;nbsp;: un ensemble de classes et de fonctions pouvant être utilisées/héritées par les plugins. C'est le lien, le langage commun entre le logiciel principal et les plugins.&lt;/li&gt;
&lt;li&gt;Les plugins se basent sur cette API, et créent ainsi de nouvelles fonctionnalités pour le logiciel principal. Ils se présentent généralement sous forme de bibliothèques dynamiques (*.dll sous Windows ou *.so sous Linux). Pour pouvoir être chargés par le programme principal, ils doivent être copiés dans un répertoire spécifique.&lt;/li&gt;
&lt;li&gt;Le logiciel principal, au démarrage, charge les plugins qu'il trouve, ajoutant ainsi de nouvelles fonctionnalités.&lt;/li&gt;
&lt;/ol&gt;


&lt;h4&gt;Avantages&amp;nbsp;?&lt;/h4&gt;


&lt;p&gt;Les avantages d'un système de plugins sont nombreux. En voici quelques uns&amp;nbsp;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;l'utilisateur ou un intervenant externe peut étendre les fonctionnalités d'une application sans avoir son code source,&lt;/li&gt;
&lt;li&gt;le logiciel est beaucoup plus modulaire&amp;nbsp;: possibilité de faire des versions réduite, version complète...&lt;/li&gt;
&lt;li&gt;la mise en place d'un système de plugin force à réfléchir un peu à l'architecture du logiciel, ce qui n'est pas un mal ;)&lt;/li&gt;
&lt;/ul&gt;


&lt;h4&gt;Les plugins avec Qt&amp;nbsp;? (pourquoi c'est pratique)&lt;/h4&gt;


&lt;p&gt;La mise en place d'un système de plugin est parfois assez lourde et nécessite par exemple de vérifier dans le programme principal si un plugin contient telle ou telle fonction. Je ne parle même pas d'un système multi-plateforme... heureusement, Qt est là.&lt;/p&gt;


&lt;p&gt;Grâce à Qt, la réalisation d'un système de plugins multi-plateforme est relativement simple&amp;nbsp;: &lt;a href=&quot;http://doc.trolltech.com/4.2/plugins-howto.html&quot; hreflang=&quot;en&quot;&gt;la documentation Qt sur le système de plugins&lt;/a&gt;.&lt;/p&gt;



&lt;h3&gt;CalcOp&lt;/h3&gt;


&lt;p&gt;Pour illustrer la création de plugin, nous allons utiliser un exemple assez simple&amp;nbsp;: un petit projet que j'ai nommé &lt;code&gt;calcop&lt;/code&gt;, et qui permet à partir de 1, 2 ou 3 variables, d'effectuer une opération au choix de l'utilisateur (par exemple des additions, multiplications, remplacement de caractères dans une chaîne...).&lt;/p&gt;


&lt;p&gt;&lt;a href=&quot;http://doc.qtfr.org/public/2006/calcop1.png&quot;&gt;&lt;img src=&quot;http://doc.qtfr.org/public/2006/.calcop1_t.jpg&quot; alt=&quot;calcop1.png&quot; /&gt;&lt;/a&gt;
&lt;a href=&quot;http://doc.qtfr.org/public/2006/calcop2.png&quot;&gt;&lt;img src=&quot;http://doc.qtfr.org/public/2006/.calcop2_t.jpg&quot; alt=&quot;calcop2.png&quot; /&gt;&lt;/a&gt;
&lt;a href=&quot;http://doc.qtfr.org/public/2006/calcop3.png&quot;&gt;&lt;img src=&quot;http://doc.qtfr.org/public/2006/.calcop3_t.jpg&quot; alt=&quot;calcop3.png&quot; /&gt;&lt;/a&gt;&lt;/p&gt;


&lt;p&gt;Ça ne sert à rien, mais le principal c'est que l'exemple est très simple, il permet donc de se concentrer sur le code lié à la gestion de plugin. Le code source est livré avec deux plugins&amp;nbsp;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;un plugin contenant des opérations mathématiques (addition, multiplication, division, soustraction, factoriel)&lt;/li&gt;
&lt;li&gt;un plugin contenant des opérations sur les chaînes (inversion de sens et remplacement dans une chaîne)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Les sources du logiciel sont téléchargeables &lt;a href=&quot;http://doc.qtfr.org/public/2006/calcop-0.2.tar.gz&quot;&gt;ici&lt;/a&gt;. Je vous conseille de les télécharger avant de vous lancer dans la lecture du tutoriel.&lt;/p&gt;



&lt;h4&gt;Le programme principal&lt;/h4&gt;


&lt;p&gt;Le programme principal est relativement simple. Je ne vais pas détailler tout le code, mais je vais me focaliser sur les parties nécessaires à la mise en place de plugins.&lt;/p&gt;


&lt;p&gt;La première chose à faire, c'est de définir un ensemble d'interfaces à nos plugins&amp;nbsp;: ce sont des classes avec seulement des fonctions virtuelles pures utilisées pour dialoguer entre l'application et les plugins. Il est possible bien entendu de définir plusieurs interfaces, pour différents types de plugin, mais dans notre cas nous n'en définissons qu'une seule, OperationInterface&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;cpp&quot;&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;class&lt;/span&gt; OperationInterface
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
&lt;span style=&quot;color: #0000ff;&quot;&gt;public&lt;/span&gt;:
    &lt;span style=&quot;color: #0000ff;&quot;&gt;virtual&lt;/span&gt; ~OperationInterface&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
    &lt;span style=&quot;color: #0000ff;&quot;&gt;virtual&lt;/span&gt; QStringList operationList&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; = &lt;span style=&quot;color: #0000dd;&quot;&gt;0&lt;/span&gt;;
    virtualbool canCalculate&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; QString opName &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; = &lt;span style=&quot;color: #0000dd;&quot;&gt;0&lt;/span&gt;;
    virtualint numVariable&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; QString opName &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; = &lt;span style=&quot;color: #0000dd;&quot;&gt;0&lt;/span&gt;;
    &lt;span style=&quot;color: #0000ff;&quot;&gt;virtual&lt;/span&gt; QString calculate&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; QString opName, QStringList variableList &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; = &lt;span style=&quot;color: #0000dd;&quot;&gt;0&lt;/span&gt;;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;;
Q_DECLARE_INTERFACE&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;OperationInterface,
                    &lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot;org.nikikko.CalcOp.OperationInterface/1.0&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;La macro &lt;code&gt;&lt;a href=&quot;http://doc.trolltech.com/4.1/qtplugin.html#Q_DECLARE_INTERFACE&quot; hreflang=&quot;en&quot;&gt;Q_DECLARE_INTERFACE&lt;/a&gt;&lt;/code&gt; permet d'indiquer lors de la compilation (à l'outil &lt;code&gt;moc&lt;/code&gt;, le précompilateur Qt) que cette classe est une interface.&lt;/p&gt;


&lt;blockquote&gt;&lt;p&gt;&lt;strong&gt;Attention&lt;/strong&gt;&amp;nbsp;: le deuxième élément de la macro &lt;code&gt;&quot;org.nikikko.CalcOp.OperationInterface&quot;&lt;/code&gt; doit obligatoirement se finir par le nom de la classe (je me suis fait avoir au début).&lt;/p&gt;&lt;/blockquote&gt;


&lt;p&gt;Le reste du code, notamment la classe &lt;code&gt;OperationManager&lt;/code&gt;, sera détaillé par la suite.&lt;/p&gt;



&lt;h4&gt;Création d'un plugin&lt;/h4&gt;


&lt;p&gt;La création du plugin est relativement simple. Il suffit de créer une classe qui hérite de notre interface &lt;code&gt;OperationInterface&lt;/code&gt;. Voici par exemple le code pour le plugin mathématique&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;cpp&quot;&gt;&lt;span style=&quot;color: #339900;&quot;&gt;#include &amp;lt;QObject&amp;gt;&lt;/span&gt;
&lt;span style=&quot;color: #339900;&quot;&gt;#include &amp;lt;operationinterface.h&amp;gt;&lt;/span&gt;
&lt;span style=&quot;color: #0000ff;&quot;&gt;class&lt;/span&gt; MathPlugin : &lt;span style=&quot;color: #0000ff;&quot;&gt;public&lt;/span&gt; QObject, &lt;span style=&quot;color: #0000ff;&quot;&gt;public&lt;/span&gt; OperationInterface
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
Q_OBJECT
Q_INTERFACES&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;OperationInterface&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;
&lt;span style=&quot;color: #0000ff;&quot;&gt;public&lt;/span&gt;:
    QStringList operationList&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
    &lt;span style=&quot;color: #0000ff;&quot;&gt;bool&lt;/span&gt; canCalculate&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; QString opName &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
    &lt;span style=&quot;color: #0000ff;&quot;&gt;int&lt;/span&gt; numVariable&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; QString opName &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
    QString calculate&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt; QString opName, QStringList variableList &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;;&lt;/pre&gt;


&lt;p&gt;Deux remarques importantes&amp;nbsp;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;la classe de base d'un plugin (qui hérite d'une classe d'interface) doit toujours hériter de &lt;code&gt;QObject&lt;/code&gt;,&lt;/li&gt;
&lt;li&gt;toutes les fonctions de l'interface doivent être définies.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;&amp;nbsp;: il est possible dans un plugin d'avoir une classe qui hérite de plusieurs interfaces, pour cela voir l'exemple plugandpaint de Qt.&lt;/p&gt;&lt;/blockquote&gt;


&lt;p&gt;Et dans le fichier source&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;cpp&quot;&gt;Q_EXPORT_PLUGIN2&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;calcop_math, MathPlugin&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;La macro &lt;code&gt;&lt;a href=&quot;http://doc.trolltech.com/4.2/qpluginloader.html#Q_EXPORT_PLUGIN2&quot; hreflang=&quot;en&quot;&gt;Q_EXPORT_PLUGIN2&lt;/a&gt;&lt;/code&gt; indique au compilateur qu'il faut exporter cette classe, et que cette classe est le point d'entrée du plugin. Pour faire simple, une classe exportée est une classe qui est visible à l'extérieur de la bibliothèque (donc par le programme principal).&lt;/p&gt;


&lt;p&gt;Enfin, il faut indiquer dans le fichier .pro que l'on souhaite créer un plugin. Voici le fichier .pro correspondant au plugin calcop_math&amp;nbsp;:&lt;/p&gt;

&lt;pre&gt;
  TEMPLATE      = lib
  CONFIG       += release plugin
  INCLUDEPATH  += ../../src
  HEADERS       = mathplugin.h
  SOURCES       = mathplugin.cpp
  TARGET        = calcop_math
  DESTDIR       = ../../bin/plugins
&lt;/pre&gt;


&lt;p&gt;Voilà quelques explications&amp;nbsp;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;TEMPLATE = lib&lt;/code&gt;&amp;nbsp;: création d'une bibliothèque&lt;/li&gt;
&lt;li&gt;&lt;code&gt;CONFIG += plugin&lt;/code&gt;&amp;nbsp;: cette bibliothèque est un plugin&lt;/li&gt;
&lt;li&gt;&lt;code&gt;TARGET = calcop_math&lt;/code&gt;&amp;nbsp;: ce plugin s'appelle calcop_math (même nom que dans la macro &lt;code&gt;Q_EXPORT_PLUGIN2&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;DESTDIR = ../../bin/plugins&lt;/code&gt;&amp;nbsp;: mettre ce plugin dans le bon répertoire (répertoire des plugins de l'application)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Voilà, c'est relativement simple à faire, et en plus c'est multi-plateforme.&lt;/p&gt;



&lt;h4&gt;Chargement des plugins dans l'application&lt;/h4&gt;


&lt;p&gt;Dernière étape, c'est le chargement des plugins dans l'application. Tout ce qui concerne la gestion des plugins se fait à travers la classe &lt;code&gt;OperationManager&lt;/code&gt; dans le programme principal. Cette classe charge les plugins, et s'occupe d'effectuer les appels nécessaires aux fonctions des plugins lors du calcul.&lt;/p&gt;


&lt;p&gt;Pour me faciliter la vie, j'ai décidé d'en faire un &lt;a href=&quot;http://fr.wikipedia.org/wiki/Singleton_%28motif_de_conception%29&quot; hreflang=&quot;fr&quot;&gt;singleton&lt;/a&gt;&amp;nbsp;: c'est pour ça que le constructeur est privé, et que la classe comporte une fonction membre statique instance. Mais le code le plus intéressant se trouve dans le constructeur de cette classe&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;cpp&quot;&gt;QDir pluginsDir = QDir&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;qApp-&amp;gt;applicationDirPath&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
    pluginsDir.&lt;span style=&quot;color: #00eeff;&quot;&gt;cd&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #666666;&quot;&gt;&amp;quot;plugins&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
    foreach &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;QString fileName, pluginsDir.&lt;span style=&quot;color: #00eeff;&quot;&gt;entryList&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;QDir::&lt;span style=&quot;color: #00eeff;&quot;&gt;Files&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
        QPluginLoader loader&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;pluginsDir.&lt;span style=&quot;color: #00eeff;&quot;&gt;absoluteFilePath&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;fileName&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
        QObject *plugin = loader.&lt;span style=&quot;color: #00eeff;&quot;&gt;instance&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
        &lt;span style=&quot;color: #0000ff;&quot;&gt;if&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;plugin&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
            OperationInterface * op = qobject_cast&amp;lt;OperationInterface *&amp;gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;plugin&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;
            &lt;span style=&quot;color: #0000ff;&quot;&gt;if&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;op&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;
                m_operationList &amp;lt;&amp;lt; op;
            &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
        &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;
    &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Nous avons trois actions importantes dans ce code&amp;nbsp;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;déplacement dans le répertoire de plugin&amp;nbsp;: les deux premières lignes vont nous permettre d'aller dans le répertoire des plugins,&lt;/li&gt;
&lt;li&gt;chargement du plugin avec la classe &lt;code&gt;&lt;a href=&quot;http://doc.trolltech.com/4.2/qpluginloader.html&quot; hreflang=&quot;en&quot;&gt;QPluginLoader&lt;/a&gt;&lt;/code&gt;&amp;nbsp;: on vérifie que le plugin est bien compatible avec la version du logiciel et de Qt, et crée une instance de l'objet racine (qui est une classe héritée de l'interface, dans notre cas ce sera une instance de &lt;code&gt;MathPlugin&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;vérification de la compatibilité du plugin&amp;nbsp;: de quelle interface hérite-t-il (ici &lt;code&gt;OperationInterface&lt;/code&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Si tout se passe bien, on enregistre le plugin dans la liste des opérations. Et voilà, c'est simple, clair et propre...&lt;/p&gt;


&lt;p&gt;La classe &lt;code&gt;QPluginLoader&lt;/code&gt; est au coeur de ce code&amp;nbsp;: c'est elle qui va se charger de créer une instance du plugin. Au passage, l'instance créé, que l'on récupère à l'aide de la fonction instance(), est statique&amp;nbsp;: si l'on utilise le même code dans une autre fonction, l'instance renvoyé sera toujours la même (ie le même pointeur).&lt;/p&gt;</description>
    
          <enclosure url="http://doc.qtfr.org/public/2006/calcop-0.2.tar.gz"
      length="11551" type="application/x-gzip" />
    
    
      </item>
    
</channel>
</rss>