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

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

Qt Quick Discussion :

Afficher un fichier QML depuis un autre


Sujet :

Qt Quick

  1. #1
    Membre actif Avatar de Altak
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Octobre 2014
    Messages
    170
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Octobre 2014
    Messages : 170
    Points : 245
    Points
    245
    Par défaut Afficher un fichier QML depuis un autre
    Bonjour,

    J'aurais quelque question sur le fonctionnement du QML et je ne trouve pas de réponse clair du coup,je viens vous les poser :p

    Est-il possible de pouvoir afficher un fichier QML depuis un autre? (je suis sur mon main.qml et j'aimerais afficher mon toto.qml dans la même fenêtre par exemple)
    Pour du portage mobile, retrouve-t-on facilement les outils google? (comme analytics ou google play service)

    Merci d'avance
    QLHF

  2. #2
    Membre émérite
    Avatar de ymoreau
    Homme Profil pro
    Ingénieur étude et développement
    Inscrit en
    Septembre 2005
    Messages
    1 154
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Ingénieur étude et développement
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2005
    Messages : 1 154
    Points : 2 834
    Points
    2 834
    Par défaut
    Tu peux déclarer des composants dans des fichiers séparés, et ensuite les importer pour les "instancier"/utiliser dans un autre code QML : http://doc.qt.io/qt-4.8/qmlreusablecomponents.html
    Je n'ai pas trouvé la page équivalente dans la doc Qt5, je ne crois pas que ce principe soit obsolète, mais peut être qu'un membre plus à jour pourra confirmer/infirmer.

  3. #3
    Responsable Qt & Livres


    Avatar de dourouc05
    Homme Profil pro
    Ingénieur de recherche
    Inscrit en
    Août 2008
    Messages
    26 618
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Ingénieur de recherche
    Secteur : Enseignement

    Informations forums :
    Inscription : Août 2008
    Messages : 26 618
    Points : 188 585
    Points
    188 585
    Par défaut
    Par exemple, pour Qt 5 : http://doc.qt.io/qt-5/qtqml-documents-definetypes.html

    Pour Google Analytics et tous les services Google, il faut savoir que Qt n'est pas un produit Google. Par contre, tu peux toujours décider de vendre ton âme à la même société, mais il faut un peu sortir des sentiers battus, par exemple http://www.ics.com/blog/using-google...cations-part-2.
    Vous souhaitez participer aux rubriques Qt (tutoriels, FAQ, traductions) ou HPC ? Contactez-moi par MP.

    Créer des applications graphiques en Python avec PyQt5
    Créer des applications avec Qt 5.

    Pas de question d'ordre technique par MP !

  4. #4
    Membre actif Avatar de Altak
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Octobre 2014
    Messages
    170
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Octobre 2014
    Messages : 170
    Points : 245
    Points
    245
    Par défaut
    Re,

    Tout d'abord, merci pour vos réponse (je vais regarder plus en détails pour l'analytics)

    Mais j'ai deux soucis:
    1) J'essaie de faire comme indiqué dans vos lien (et ca fonctionnait bien vendredi) mais la, ca me retourne une erreur "customItems is not a type"
    Voici mon code:

    main.qml
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
     
    import QtQuick 2.3
    import QtQuick.Controls 1.2
    import QtQuick.Window 2.0
     
    import MyLib 1.0
     
    ApplicationWindow {
        visible: true
        width: Screen.width * 0.8
        height: Screen.height * 0.8
        minimumWidth: Screen.width * 0.8
        minimumHeight:Screen.height * 0.8
     
        title: qsTr("toto")
     
        HomePage{
            id:body
            anchors.fill : parent
        }
    }
    HomePage.qml:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
     
     
    import QtQuick 2.0
    import QtQuick.Layouts 1.1
    import QtQuick.Controls 1.4
    import QtQuick.Controls.Styles 1.4
     
    GridLayout {
        id:homePage
        rows:2
        width: parent.width
        height: parent.height - 70
        anchors.fill: parent
        Layout.minimumHeight: 400
        anchors.bottom:parent.bottom
     
        Item {
            width:homePage.width
            height:homePage.height / 2
     
            Layout.row: 0
            Rectangle {
                id:topScreen
                color:"#ffffff"
                border.width: 0
                anchors.fill: parent
     
                GridLayout {
                    id:topScreenGridLayout
                    rows:3
                    anchors.centerIn: topScreen
     
                    Image {
                        id: image1
                        Layout.row:0
                        height: parent.height /3
                        fillMode: Image.PreserveAspectFit
                        anchors.horizontalCenter: topScreenGridLayout.horizontalCenter
                        source: "ressources/ressources/item_banch_icon.png"
                    }
     
                    Image {
                        id: image2
                        Layout.row:1
                        height: parent.height /3
                        fillMode: Image.PreserveAspectFit
                        anchors.horizontalCenter: topScreenGridLayout.horizontalCenter
                        source: "ressources/ressources/text_name_config_tryba.png"
                    }
     
                    Button {
                        Layout.row: 2
                        height:parent.height /3
                        anchors.horizontalCenter: topScreenGridLayout.horizontalCenter
                        style: ButtonStyle {
                            background: Image {
                                source:"ressources/ressources/btn_green_lg.png"
                            }
                            label: Text {
                                verticalAlignment: Text.AlignVCenter
                                horizontalAlignment: Text.AlignHCenter
                                color: "#ffffff"
                                text:qsTr("COMMENCER LA CONFIGURATION")
                                font.bold: true
                                font.pointSize: 20
                            }
                        }
                    }
                }
            }
            anchors.top: parent.top
        }
     
        Item {
            id:botScreen
            width: homePage.width
            height: homePage.height / 2
            anchors.bottom:parent.bottom
            Layout.row: 1
            Rectangle {
                color:"#c5c5c7"
                border.width: 0
                anchors.fill: parent
            }
        }
     
    }
    Les deux qml se trouvent dans le même répertoire et ca me retourne cette erreur du coup:
    "QQmlApplicationEngine failed to load component
    qrc:/main:18 HomePage is not a type"

    Je ne vois pas ce qui cloche
    Surtout que QtCreator trouve bien mes qml quand je ctrl+clic dessus...

    2) Ce que je voulais a la base c'est plutôt de faire un changement de page, de ce genre la:
    J'ai un splashScreen comme cela :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
     
     
    import QtQuick 2.3
    import QtQuick.Window 2.0
    import QtQuick.Controls 1.2
     
    import MyLib 1.0
     
    ApplicationWindow {
        visible: true
        width: Screen.width * 0.8
        height: Screen.height * 0.8
        minimumWidth: Screen.width * 0.8
        minimumHeight:Screen.height * 0.8
     
        Timer {
            interval: 500; running: true; repeat: false
            onTriggered: viewManager.showFile("qrc:/main");
        }
     
        Image {
            anchors.fill: parent
            fillMode: Image.PreserveAspectFit
            source: "ressources/ressources/splash.jpg"
        }
     
        ViewManager {
            id:viewManager
        }
    }
    Qui doit au bout d'un certain temps m'afficher ma main page.
    Du coup, j'ai fais une classe ViewManager qui s'occupera de passer d'une vue a l'autre (voici le code c++) :

    Code qt : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
     
     
    #include <iostream>
     
    #include "viewmanager.h"
     
    ViewManager::ViewManager(QObject *parent) : QObject(parent)
    {
     
    }
     
    void        ViewManager::showFile(const QString &fileName) {
        std::cout << "check to show "<< std::endl;
        QQmlApplicationEngine engine;
        engine.load(QUrl(fileName));
    }
     
    //SETTER
    void        ViewManager::setCurrentView(const QString &aliasView) {
        this->m_currentView = aliasView;
    }
     
    //GETTER
    QString     ViewManager::currentView() {
        return this->m_currentView;
    }

    Mais ca ne m'affiche rien Vous avez une solution?

    Merci en tout cas

    GL HF

  5. #5
    Membre à l'essai
    Profil pro
    Inscrit en
    Janvier 2010
    Messages
    27
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2010
    Messages : 27
    Points : 16
    Points
    16
    Par défaut
    Les deux qml se trouvent dans le même répertoire et ca me retourne cette erreur du coup:
    "QQmlApplicationEngine failed to load component
    qrc:/main:18 HomePage is not a type"
    Il faut que tu inserts import "chemin vers /HomePage.qml" dans main.qml pour résoudre cette erreur.

  6. #6
    Membre actif Avatar de Altak
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Octobre 2014
    Messages
    170
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Octobre 2014
    Messages : 170
    Points : 245
    Points
    245
    Par défaut
    Re,

    Au final, j'ai trouvé une solution a mes problèmes :O

    Mon problème d'import venais de mes alias dans mon .qrc: Apriori, appelé un fichier avec un alias depuis un qml ne fonctionne pas (va savoir pourquoi :O). Du coup, j'ai viré mes alias et la, ca fonctionne correctement.
    Et pour changement de vue, j'utilise au final un Layout global avec un container et j'y met mes layout dedans

    J'ai un dernier petit soucis:
    Le manque de tuto/doc, l'un de vous aurez un site avec de bon tuto sur du QML?

    GL HF

Discussions similaires

  1. Réponses: 1
    Dernier message: 25/03/2008, 17h40
  2. accès à un fichier excel depuis un autre fichier excel
    Par Patnel dans le forum Macros et VBA Excel
    Réponses: 3
    Dernier message: 08/11/2007, 15h09
  3. [EasyPHP] impossible d'afficher mon site web depuis un autre PC
    Par bcd_30 dans le forum EDI, CMS, Outils, Scripts et API
    Réponses: 3
    Dernier message: 12/10/2007, 15h30
  4. appeler la fonction d'un fichier js depuis un autre fichier
    Par kohsaka dans le forum Général JavaScript
    Réponses: 3
    Dernier message: 13/09/2007, 18h49
  5. [Stratégie] Afficher des fichiers PDF depuis une base Oracle
    Par tetram51 dans le forum Développement Web en Java
    Réponses: 3
    Dernier message: 20/12/2005, 09h15

Partager

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