Unsolved Some questions about QSharedMemory
-
Hi
I want to useQSharedMemory
instead ofQtDBus
between a plugin and main program.
But I still confuse about that as follow:- How to insert data into
QSharedMemory
after Icreate(128)
(e.g.). Should I usememcpy
to copy my data intoQSharedMemory::data()
? - Is it necessary that put the data into
QBuffer
then put thatQBuffer
intoQDataStream
and copyQDataStream
into theQSharedMemory
finally? - How can I put a
struct
into?
Regards
Mihan - How to insert data into
-
@Mihan said in Some questions about QSharedMemory:
I want to use QSharedMemory instead of QtDBus between a plugin and main program.
Why on both counts? You have the plugin and the program in the same address space, why do you feel you need IPC primitives to begin with?
-
@kshegunov
I don't quite understand it. Maybe I misunderstandQt Plugin
.
If I don't useQSharedMemory
orQtDbus
, how does the main program communicate with plugins? -
@Mihan said in Some questions about QSharedMemory:
I don't quite understand it. Maybe I misunderstand
Qt Plugin
.It seems so, yes.
If I don't use
QSharedMemory
orQtDbus
, how does the main program communicate with plugins?Well, the usual way. The plugin is loaded and as a dynamically loaded library lives in the same address space as the loading process. Thus the main program operates with it as any other component it itself provides. The plugin exposes an entry point object, from where the program can query the actual plugin and do stuff. There are real good examples in the docs, have you looked at them?
-
@kshegunov NO, I just know how to make a plugin.
Cus I create my input plugin in
main.cpp
byqputenv
:qputenv("QT_IM_MODULE", QByteArray("Qt5Input"));
but now I want to make a USB hotplug check, it also has json to name it, but I don't know how t use it.
-
@Mihan said in Some questions about QSharedMemory:
NO, I just know how to make a plugin.
Cus I create my input plugin in main.cpp by qputenvSetting an environment variable doesn't a plugin make.
Depending on the type of plugin there's a base class you derive from (for generic ones it'sQObject
). Then you load the plugins into the main application (if it's an application plugin, if it's a Qt plugin it's loaded automatically).Read here: https://doc.qt.io/qt-5/plugins-howto.html
And here: https://doc.qt.io/qt-5/qpluginloader.htmlAnd here are a couple of decent examples:
https://doc.qt.io/qt-5/qtwidgets-tools-echoplugin-example.html
https://doc.qt.io/qt-5/qtwidgets-tools-plugandpaint-app-example.html -
Thanks @kshegunov
I wil redo my plugin