From b32681d8fe24bea2784470c11fa8ca129a46db3b Mon Sep 17 00:00:00 2001 From: ppouchet <pierre.pouchet@etu.ec-lyon.fr> Date: Sun, 23 Mar 2025 14:23:03 +0100 Subject: [PATCH] Ajout debugs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit tentative de faire marcher la lecture de la liste de mots et de l'image, mais ça ne marche toujours pas --- Motus/CMakeLists.txt | 19 +++++++++++++------ Motus/Choosebutton.qml | 28 ++++++++++++++++++++++++++++ Motus/Main.qml | 24 ++++++++++++++++++++++++ Motus/Ressources.qrc | 1 + Motus/wordchooser.cpp | 18 ++++++++++++++---- 5 files changed, 80 insertions(+), 10 deletions(-) create mode 100644 Motus/Choosebutton.qml diff --git a/Motus/CMakeLists.txt b/Motus/CMakeLists.txt index e9ddbc6..5a9421c 100644 --- a/Motus/CMakeLists.txt +++ b/Motus/CMakeLists.txt @@ -15,14 +15,21 @@ qt_add_executable(appMotus qt_add_qml_module(appMotus URI Motus VERSION 1.0 + QML_FILES Main.qml - RESOURCES Ressources.qrc - QML_FILES Case.qml - QML_FILES Key.qml - QML_FILES BackKey.qml - QML_FILES Bouton.qml - SOURCES wordchooser.h wordchooser.cpp + Case.qml + Key.qml + BackKey.qml + Bouton.qml + Choosebutton.qml + + SOURCES + wordchooser.h + wordchooser.cpp + + RESOURCES + Ressources.qrc ) # Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1. diff --git a/Motus/Choosebutton.qml b/Motus/Choosebutton.qml new file mode 100644 index 0000000..c5b0fb0 --- /dev/null +++ b/Motus/Choosebutton.qml @@ -0,0 +1,28 @@ +import QtQuick +import QtQuick.Controls 2.15 + +Item { + property alias buttonText: button.text + width: 300 + height: 200 + Rectangle { + id: rectangle + x: 0 + y: 0 + width: 300 + height: 200 + color: "#ffffff" + + Button { + id: button + x: 2 + y: 0 + width: 298 + height: 200 + text: qsTr("Bouton") + } + } + + + +} diff --git a/Motus/Main.qml b/Motus/Main.qml index ac3f942..5849c59 100644 --- a/Motus/Main.qml +++ b/Motus/Main.qml @@ -57,6 +57,27 @@ Window { } } + Choosebutton { + id: choosebutton + x: 663 + y: 249 + buttonText: "Générer un mot" + + MouseArea { + id: mouseArea1 + x: 0 + y: 0 + width: 400 + height: 200 + onClicked: { + let mot = wordChooser.getRandomWord(); + console.log("Mot choisi :", mot); + case3._textText = mot; + onClicked: case3._textColor="#51c3e1"; + } + } + + Image { id: testImage @@ -390,6 +411,8 @@ Window { } } + + Keys.onPressed: (event) => { if (event.key === Qt.Key_A) { case1._textText = qsTr("C"); @@ -399,3 +422,4 @@ Window { } } } +} diff --git a/Motus/Ressources.qrc b/Motus/Ressources.qrc index 6c7eb07..10ea4bd 100644 --- a/Motus/Ressources.qrc +++ b/Motus/Ressources.qrc @@ -6,5 +6,6 @@ <file>Key.qml</file> <file>words_alpha.txt</file> <file>back_key.png</file> + <file>Choosebutton.qml</file> </qresource> </RCC> diff --git a/Motus/wordchooser.cpp b/Motus/wordchooser.cpp index fe0abe6..a0aedbd 100644 --- a/Motus/wordchooser.cpp +++ b/Motus/wordchooser.cpp @@ -2,14 +2,17 @@ #include <QFile> #include <QTextStream> #include <QRandomGenerator> -QFile file("words_alpha.txt"); + + +#include <QDebug> + WordChooser::WordChooser(QObject *parent) : QObject(parent) { loadWords(); } void WordChooser::loadWords() { - QFile file("qrc:/words_alpha.txt"); + QFile file(":/words_alpha.txt"); // ✅ fonctionne avec le .qrc if (file.open(QIODevice::ReadOnly | QIODevice::Text)) { QTextStream in(&file); while (!in.atEnd()) { @@ -18,13 +21,20 @@ void WordChooser::loadWords() { words.append(line); } file.close(); + qDebug() << "✅ Mots chargés :" << words.size(); + } else { + qDebug() << "❌ Erreur : impossible d'ouvrir words_alpha.txt"; } } QString WordChooser::getRandomWord() { - if (words.isEmpty()) + if (words.isEmpty()) { + qDebug() << "❌ Aucune donnée chargée dans words."; return ""; + } int index = QRandomGenerator::global()->bounded(words.size()); - return words[index]; + QString mot = words[index]; + qDebug() << "✅ Mot choisi :" << mot; + return mot; } -- GitLab