运行QtRemoteObjects时得到“未分配动态元对象”

问题描述 投票:0回答:1

我尝试使用QRemoteObjects共享两个以上的对象,但在运行client.py示例时收到“未分配动态元对象”警告,但我找不到发生的情况,我的示例运行良好,任何人都可以给我一些建议吗?

server.py

from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5.QtRemoteObjects import *
from faker import Faker

fake = Faker()

class Name(QObject):
    sig_name = pyqtSignal(str)

    def __init__(self):
        super().__init__()
        self.name = ''
        self.startTimer(1000)

    def timerEvent(self, event):
        self.name = fake.name()
        self.sig_name.emit(self.name)

class Email(QObject):
    sig_email = pyqtSignal(str)

    def __init__(self):
        super().__init__()
        self.startTimer(1000)

    def timerEvent(self, event):
        self.sig_email.emit(fake.email())


class Server(QObject):
    def __init__(self):
        super().__init__()
        self.name = Name()
        self.email = Email()

        host = QRemoteObjectHost(QUrl('local:server'), self)
        r1 = host.enableRemoting(self.name, 'name')
        r2 = host.enableRemoting(self.email, 'email')

        print([r1, r2])

    def print_name(self, x):
        print(x)

app = QCoreApplication([])
s = Server()
app.exec()

client.py

from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5.QtRemoteObjects import *

class Client(QObject):
    def __init__(self):
        super().__init__()
        node = QRemoteObjectNode(self)
        node.connectToNode(QUrl("local:server"))

        self.remote_name = node.acquireDynamic('name')
        self.remote_email = node.acquireDynamic('email')

        self.remote_name.initialized.connect(self.onInitName)
        self.remote_email.initialized.connect(self.onInitEmail)

    def onInitName(self):
        self.remote_name.sig_name.connect(self.print_info)

    def onInitEmail(self):
        self.remote_email.sig_email.connect(self.print_info)

    def print_info(self, x):
        print('-->:', x)

app = QCoreApplication([])
c = Client()
app.exec()

在终端1中运行python server.py并在终端2中运行python client.py之后。在第二航站楼,我收到如下警告。“

python python-3.x pyqt pyqt5 qtremoteobjects
1个回答
0
投票

在C ++中,您可以使用2种方法购买副本:

© www.soinside.com 2019 - 2024. All rights reserved.