Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Send string signal from combobox in qml
Forum Updated to NodeBB v4.3 + New Features

Send string signal from combobox in qml

Scheduled Pinned Locked Moved Unsolved Qt for Python
1 Posts 1 Posters 181 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    Fakhr
    wrote on last edited by
    #1

    I'm trying to send a string from combobox to an api. Unfortunately nothing is being sent.

    main.qml

    import QtQuick 2.15
    import QtQuick.Window 2.15
    import QtQuick.Controls 2.15
    Window {
        id: mainWindow
        width: 1120
        height: 680
        visible: true
    
        Rectangle {
            id: mainBody
            color: "#F4F4F5"
            anchors.fill: parent
    
            ComboBox {
                id: comboBox
                    x: 219
                    y: -9
                    width: 504
                    height: 40
                    model: [ "hp", "lenovo", "acer"]
            }
            Button {
                id: bt
                width: 24
                height: 24
                onClicked: backend.add(comboBox.text)
            }
        }
        Connections {
            target: backend
        }
    }
    

    main.py

    # This Python file uses the following encoding: utf-8
    import os
    # from pathlib import Path
    import sys
    import json
    import requests
    from PySide2.QtWidgets import QApplication
    from PySide2.QtQml import QQmlApplicationEngine
    from PySide2.QtCore import Slot, Signal, QObject
    
    class MainWindow(QObject):
        def __init__(self):
            QObject.__init__(self)
    
        signalcombo = Signal(str)
        @Slot(str, str, str)
    
        def add(self, getCombo):
            putdata1 = {"category_name": getCombo}
            data1 = 
            requests.post("random api", json=putdata1)
            print(data1.text)
    if __name__ == "__main__":
        app = QApplication(sys.argv)
        engine = QQmlApplicationEngine()
    
        # engine.load(os.fspath(Path(__file__).resolve().parent / "qml/main.qml"))
        engine.load(os.path.join(os.path.dirname(__file__), "qml/main.qml"))
    
        # Get Context
        main = MainWindow()
        engine.rootContext().setContextProperty("backend", main)
        if not engine.rootObjects():
            sys.exit(-1)
        sys.exit(app.exec_())
    

    Now the problem is that when data1.text is printed it says "Inserted Successfully", but there is nothing in the database not even blank space. No data is being sent. Can anyone help me. This approach is working for textField but not for combobox.

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved