获得 "Dynamic metaobject is not assigned" 而 运行 QtRemoteObjects
Got "Dynamic metaobject is not assigned" while run QtRemoteObjects
我尝试使用QRemoteObjects
来共享两个以上的对象但是
我在 运行 client.py 示例时收到 "Dynamic metaobject is not assigned" 警告,但我不知道发生了什么,我的示例工作正常,谁能给我有什么建议吗?
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()
在第一航站楼 运行 python server.py
和第二航站楼 运行 python client.py
之后。
我在二号航站楼收到如下警告。
在 C++ 中,您可以使用 2 种方法购买副本:
QRemoteObjectNode::acquire()
:
SimpleSwitchReplica *rep = repNode.acquire<SimpleSwitchReplica>("SimpleSwitch"));
QRemoteObjectNode::acquireDynamic()
:
QRemoteObjectDynamicReplica *rep = repNode.acquireDynamic("SimpleSwitch");
正如观察到的第二种方法,使用了一个 QRemoteObjectDynamicReplica
对象,它是 class 通过复制属性、信号和插槽即时创建的对象,但不包含所有节点的信息 class 所以它不是一个精确的副本所以它有缺点 the docs 指出:
There are generated replicas (replicas having the header files
produced by the Replica Compiler), and dynamic replicas, which are
generated on-the-fly. This is the class for the dynamic type of
replica.
When the connection to the Source object is made, the initialization
step passes the current property values (see Replica Initialization).
In a DynamicReplica, the property/signal/slot details are also sent,
allowing the replica object to be created on-the-fly. This can be
conventient in QML or scripting, but has two primary disadvantages.
First, the object is in effect "empty" until it is successfully
initialized by the Source. Second, in C++, calls must be made using
QMetaObject::invokeMethod(), as the moc generated lookup will not be
available.
(强调我的)
而对于 PyQt,它仅支持第二种方法,因此您会收到指示可能存在问题的警告消息。
我尝试使用QRemoteObjects
来共享两个以上的对象但是
我在 运行 client.py 示例时收到 "Dynamic metaobject is not assigned" 警告,但我不知道发生了什么,我的示例工作正常,谁能给我有什么建议吗?
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()
在第一航站楼 运行 python server.py
和第二航站楼 运行 python client.py
之后。
我在二号航站楼收到如下警告。
在 C++ 中,您可以使用 2 种方法购买副本:
QRemoteObjectNode::acquire()
:SimpleSwitchReplica *rep = repNode.acquire<SimpleSwitchReplica>("SimpleSwitch"));
QRemoteObjectNode::acquireDynamic()
:QRemoteObjectDynamicReplica *rep = repNode.acquireDynamic("SimpleSwitch");
正如观察到的第二种方法,使用了一个 QRemoteObjectDynamicReplica
对象,它是 class 通过复制属性、信号和插槽即时创建的对象,但不包含所有节点的信息 class 所以它不是一个精确的副本所以它有缺点 the docs 指出:
There are generated replicas (replicas having the header files produced by the Replica Compiler), and dynamic replicas, which are generated on-the-fly. This is the class for the dynamic type of replica.
When the connection to the Source object is made, the initialization step passes the current property values (see Replica Initialization). In a DynamicReplica, the property/signal/slot details are also sent, allowing the replica object to be created on-the-fly. This can be conventient in QML or scripting, but has two primary disadvantages. First, the object is in effect "empty" until it is successfully initialized by the Source. Second, in C++, calls must be made using QMetaObject::invokeMethod(), as the moc generated lookup will not be available.
(强调我的)
而对于 PyQt,它仅支持第二种方法,因此您会收到指示可能存在问题的警告消息。