I’m trying to get data from an api and insert it into table view from python side. Code.
main.qml
import QtQuick 2.15
import QtQuick.Window 2.15
import QtQuick.Controls 1.4
import QtQuick.Controls 2.15
Window {
width: 1200
height: 500
visible: true
title: qsTr("TableView")
Rectangle {
anchors.fill: parent
color: "#50505f"
TableView {
id: table
anchors.fill: parent
model: libraryModel
rowDelegate: Rectangle {
color: styleData.selected ? "5a53ff" : "#40405f"
width: 2000
height: 40
border.width: 1
}
TableViewColumn {
role: "title"
title: "Title"
width: 500
}
TableViewColumn {
role: "author"
title: "Author"
width: 500
}
}
}
// Connections {
// target: backend
// }
}
main.py
# This Python file uses the following encoding: utf-8
import os
import sys
from turtle import title
import requests
import json
from PySide2.QtCore import QObject, Slot, Signal
from PySide2.QtWidgets import QApplication
from PySide2.QtQml import QQmlApplicationEngine
if __name__ == "__main__":
app = QApplication(sys.argv)
engine = QQmlApplicationEngine()
# Get Context
# main = MainWindow()
url = "http://localhost:8085/api/supplier"
response = requests.get(url).json()
id = []
name = []
for obj in response:
id.append(obj["supplier_id"])
id.append(obj["supplier_name"])
myModel = []
engine.rootContext().setContextProperty("libraryModel", id)
engine.load(os.path.join(os.path.dirname(__file__), "main.qml"))
if not engine.rootObjects():
sys.exit(-1)
sys.exit(app.exec_())
I understand what the error is, basically when the it calls the api it sets the first value it gets and sets it to both the fields, I want the data to be separated (id should go to title and name to author), but I can’t seem to find a way to do it. Any help would be really appreciated. I’ve been working on it for quite a while and can’t find a solution.
You may also like…
- Why fluentd loss most of it's log while using http output plugin (in similar timestamp)
- Java Mouse Listener – Can event type be detected inside of an event?
- flutter build ipa works locally, but not when run on github actions on the same machine
- CSS Imported by a Dependency
- Module '"rxjs"' has no exported member 'firstValueFrom'
- what use spring multiple handler websocket session service
- Failing to increment pair count correctly add_pairs Tideman CS50
- How can I get the average cost from a specific column from a table in R
- The theme system is not working for me and I'm not sure why
- Sorting multiple rows of un-sorted data based on text string – GSheets
- Tkinter RuntimeError: main thread is not in main loop when trying to insert item into listbox from different thread
- SwiftUI: Generating a continuous alphabetical list (from a-z then from aa, bb, cc, …, aaa, bbb, ccc)
- AWS Eventbridge rule trigger once all in-flight sqs messages are processed
- Avoid calling a method in a loop
- How to add a single value in datagridview with c#?
- MenuItem with onClick={popupState.close} in Material-ui V 5.0 how to execute a Link to open the component?
amazon-web-services android angular api arrays c# css dart dataframe django docker excel express firebase flutter html ios java javascript jquery json kotlin laravel linux list mongodb mysql node.js pandas php postgresql python python-3.x r react-native reactjs regex spring spring-boot sql sql-server string swift typescript vue.js