I am writing a plugin for another application. I want to support the plugin on multiple platforms, so I am strongly considering using Qt.
The plugin needs to be able to show some basic GUI. The plugin interface does not in any way handle GUI - it is just a simple DLL/shared library specified with a C-header file.
Can I use Qt inside such a shared library? The calling application might or might not be using Qt itself. Any hints on what to do? Do I need to run a QApplication event-loop in a separate thread? Or can I just call the event-loop myself while waiting for input? (I only need modal dialogs).
I don't think it is possible because you need to create the QApplication eventloop in the main thread.
Note that QCoreApplication::exec()
must always be called from the main
thread (the thread that executes
main()), not from a QThread. In GUI
applications, the main thread is also
called the GUI thread because it's the
only thread that is allowed to perform
GUI-related operations.
Related
I am using Qt5 for off-screen rendering and have a segmentation fault when running inside Docker.
I have the code inside a c++ and calling the function via python using pybind11
This is the code causing the segfault
QSurfaceFormat glFormat;
glFormat.setVersion(3, 3);
glFormat.setProfile(QSurfaceFormat::CoreProfile);
glFormat.setRenderableType(QSurfaceFormat::OpenGL);
surface = new QOffscreenSurface();
surface->setFormat(glFormat);
surface->create(); // <-- Here
The exact error is :
QObject::connect: Cannot connect (null)::destroyed(QObject*) to QOffscreenSurface::screenDestroyed(QObject*)
I tried to run it via xvfb-run -a python prg.py and got the same error
Any pointers to debug this?
A little more context to the issue , the above code works fine if I use it inside main thread wrapped in QApplication. This problem occurs only when I move it inside a function so I can call it inside python.
Your last clue about running outside of the main thread is probably the problem you are running into.
Looking at the docs https://doc.qt.io/qt-5/qoffscreensurface.html#details:
Note: Due to the fact that QOffscreenSurface is backed by a QWindow on
some platforms, cross-platform applications must ensure that create()
is only called on the main (GUI) thread. The QOffscreenSurface is then
safe to be used with makeCurrent() on other threads, but the
initialization and destruction must always happen on the main (GUI)
thread.
So the solution would probably be to create the surface in the main thread and then just use it like you need it via pybind11.
I got error when execute code. I think it's not related to code. something is missing.
java.lang.IllegalStateException: Problem in some module which uses Window System: Window System API is required to be called from AWT thread only, see http://core.netbeans.org/proposals/threading/
You have flagged your post with JavaFX, so I assume you are talking about a JavaFX application. Every GUI update in the JavaFX-world is done on the JavaFX application thread. Your exception however indicates that you are using some AWT code in your program which has a different requirement. It must be run on AWT thread. So, the first thing you have to do is find out what this code is and then you have to make sure to call it on the right thread. You can use Platform.runLater() to put something on the JavaFX thread and SwingUtilities.invokeLater() to put something on the AWT thread.
I am working on an application which interact with a database and construct reports, I want this application to be extensible and I can in the future to integrate custom report builders to the application as plugins.
I have some question about the plugin architecture supported by Qt:
Can I load the plugins in there own processes ?
How could I send some custom QML type from the plugin to main application and hook some event handlers on it.
Another question: is there any framework to develop service based qt application ?
Can I load the plugins in there own processes ?
Not with the plugin mechanism (QPluginLoader). The plugin mechanism dynamically loads libraries (different threads are possible). However, your plugins can be a normal application, that gets started by your main application via QProcess, and exchange data via stdin/stdout (or other IPC mechanisms)
How could I send some custom QML type from the plugin to main application and hook some event handlers on it.
In case you use normal plugins, simply add method that returns the created QML object. Have a look at:https://doc.qt.io/qt-5/qtqml-cppintegration-interactqmlfromcpp.html#loading-qml-objects-from-c
In case you want to use the multi process version, it gets slightly more complicated. Pass the QML code via stdout and create it in your main application. Pass some "communicator" object to this created QML object, so that the QML type can send back data via that communicator to it's original process.
I have a requirement for creating a singleton for QTimer across my program. The problem is that when the QTimer object times out, I get a segmentation fault.
I am currently using qt creator and the debug stack shows the crash on activation() call of the moc_ class for the same on the timeout event.
My current project uses the component architecture template(basically something like a star structure where multiple components communicate via a central component) and I intend to use the class over multiple components.
I originally created the same code on a separate project using the basic template where the code was working.
Hence, this brings me to my question; are QObjects not allowed to exist as singletons over multiple components in a component structure?
I use qtscript in an application to provide automation capabilities for various functions within the application.
To allow greater flexibility i need the possibility to execute other tools (commandline commands/applications) from the script and get their output (the application itself is not security relevant - so calling random code may be ok).
Is their a way to do this with the basic qtscript module or some 3rd party class that encapsulate this or do i have to do this on my own?
A process can be spawned via QProcess class. It also provides console I/O capabilities to fetch executed process output (standard and error).
You will need to have a wrapper class however, since QProcess cannot be exposed directly to script environment (e.g. it defines no public slots accessible to a script).
See Related discussion on qtcentre forum.