python 动态加载qml,启动时的PyQt加载功能(qml加载程序)

嗨,我有以下问题:

这是我的工作代码import sys

from PyQt5.QtCore import QObject, QUrl, Qt

from PyQt5.QtWidgets import QApplication

from PyQt5.QtQml import QQmlApplicationEngine

import os

import vlc

from time import sleep

# define VLC instance

instance = vlc.Instance()

# Define VLC player

instance = vlc.Instance('--input-repeat=-1', '--fullscreen')

player = instance.media_player_new()

list_test = []

list_name = []

def prepare_url(url):

media = instance.media_new(url)

player.set_media(media)

if __name__ == "__main__":

os.environ["QT_QUICK_CONTROLS_STYLE"] = "Material"

app = QApplication(sys.argv)

engine = QQmlApplicationEngine()

ctx = engine.rootContext()

ctx.setContextProperty("main", engine)

engine.load('SimpleQML.qml')

win = engine.rootObjects()[0]

win.show()

button = win.findChild(QObject, "playBtn")

def myFunction():

print("A fine piece of text")

button.clicked.connect(myFunction) # works on click

myFunction() #works with out clicking

sys.exit(app.exec_())

现在,我想通过以下代码对此进行扩展:

^{pr2}$

最后这就是错误das

Traceback (most recent call last):

File "/home/flea/Desktop/quick qt/main.py", line 65, in

list_fill()

File "/home/flea/Desktop/quick qt/main.py", line 55, in list_fill

comboBox.clear()

AttributeError: 'QObject' object has no attribute 'clear'

我试图用硬编码的list来做ti,但是list并不是问题所在,因为某些原因,python无法识别我的组合框,我不确定这里有什么问题。

我可以加载我的按钮并向其添加一个单击事件(这很有效),但我不能将列表添加到我的组合框中。在

这是我的Qmlimport QtQuick 2.10

import QtQuick.Controls 2.1

import QtQuick.Window 2.2

import QtQuick.Controls.Material 2.3

ApplicationWindow {

id: applicationWindow

Material.theme: Material.Light

title: qsTr("Test Invoke")

width: 600

height: 500

Row {

id: row

width: 200

height: 400

anchors.left: parent.left

anchors.leftMargin: 5

anchors.top: parent.top

anchors.topMargin: 5

Button{

id: playBtn

objectName: "playBtn"

text : "Play"

checked: false

padding: 6

rightPadding: 8

font.wordSpacing: 0

font.pointSize: 10

font.family: "Times New Roman"

topPadding: 4

highlighted: true

Material.accent: Material.Red

}

Button {

id: stopBtn

objectName: "stopBtn"

text: qsTr("Stop")

anchors.left: playBtn.right

anchors.leftMargin: 5

}

Button {

id: stfBtn

text: qsTr("Save")

objectName: "stfBtn"

anchors.left: stopBtn.right

anchors.leftMargin: 5

}

Button {

id: minimize

objectName: "minBtn"

text: qsTr("Min")

anchors.left: stfBtn.right

anchors.leftMargin: 5

}

}

Column {

id: column

x: 135

y: 100

width: 200

height: 400

TextField {

objectName: "nameText"

id: nameText

width: 300

text: qsTr("")

}

TextField {

objectName: "urlText"

id: urlText

width: 300

text: qsTr("")

}

ComboBox {

objectName: "comboBox"

id: comboBox

width: 200

}

}

Slider {

id: slide

objectName: "slider"

x: 160

y: 311

value: 0.5

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值