- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我尝试使用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()
在我在终端一运行python server.py
并在终端二运行python client.py
之后。我在二号航站楼收到了如下警告。
最佳答案
在 C++ 中,您可以使用 2 种方法购买副本:
QRemoteObjectNode::acquire()
: SimpleSwitchReplica *rep = repNode.acquire<SimpleSwitchReplica>("SimpleSwitch"));
QRemoteObjectNode::acquireDynamic()
:
QRemoteObjectDynamicReplica *rep = repNode.acquireDynamic("SimpleSwitch");
观察第二种方法时,使用了QRemoteObjectDynamicReplica
,它是一个通过复制属性、信号和槽动态创建的类对象,但不包含节点类,因此它不是精确的副本,因此具有 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,它仅支持第二种方法,因此您会收到指示可能存在问题的警告消息。
关于python - 运行 QtRemoteObjects 时得到 "Dynamic metaobject is not assigned",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59624965/
moc_mm.o: In function `Counter::metaObject() const': moc_mm.cpp:(.text+0x0): multiple definition of
我正在创建一组具有通用基本类型的 Qt 插件。该应用程序加载一个插件并根据它是哪个基类型的子类对其提供的类进行分类。 基本类型包含在静态库中,派生类型内置到包含静态库的插件中,应用程序还链接到静态库。
在将 Qt 与 Vs 集成并尝试编译 .pro 文件后,我收到以下错误: Error 9 error LNK2001: unresolved external symbol "public:
我一直在使用旧项目的构建脚本,并且在Gradle 2.13中收到以下错误。 myhost jthoms$ gradle clean build To honour the JVM settings f
我在 Foo 类中声明了一个函数: Q_INVOKABLE void setImageUrl(const QString &imageUrl); 但是我无法获取该方法的函数索引: Foo* foo =
我尝试使用QRemoteObjects来共享两个以上的对象,但是我在运行 client.py 示例时收到“动态元对象未分配”警告,但我不知道发生了什么,我的示例工作正常,任何人都可以给我一些建议吗?
就在我开始之前,我已经搜索了 SO 和谷歌很长时间试图解决这个问题,但没有成功。 我正在尝试编译我的项目,该项目过去使用某个库来提供基于 Windows 窗体的 GUI 功能。现在我的公司已经开始迁移
我是一名优秀的程序员,十分优秀!