Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Can I use Qt in plugins?
QtWS25 Last Chance

Can I use Qt in plugins?

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 825 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    yr.zh
    wrote on last edited by yr.zh
    #1

    There are some programs have ability to load and unload modules dynamically at runtime, but not using Qt framework(such us vlc). The "plugins" imply these modules.
    If I want to provide a image-related plugin, can I use QtGUI (QImage) to implement it? As the documentation said, there should be a QGuiApplication instance. The questions are, where should it be instantiated and who maitain it?

    For any GUI application using Qt, there is precisely one QGuiApplication object no matter whether the application has 0, 1, 2 or more windows at any given time. For non-GUI Qt applications, use QCoreApplication instead, as it does not depend on the Qt GUI module. For QWidget based Qt applications, use QApplication instead, as it provides some functionality needed for creating QWidget instances.
    

    Consider the following cases:
    case 1:
    If there are two plugins called PA and PB, they both rely on QGuiApplication, PA is loaded before PB. At PA's initialization, PA attemp to get an instance of application with QCoreApplication::instance(), and get a NULL, then PA instantiate a QGuiApplication. There is an instance and PB will be loaded. PB can't create an another QGuiApplication instance, but it can obtain the exist one. Now, PA finish its work and is about to be unloaded. Should PA destroy the instance of QGuiApplication while PB is still using it?
    case 2:
    PA is a plugin rely on QtGui, PB is a plugin rely on QtWighet. PA is loaded before PB, PA create a QGuiApplication at its initialization, how can PB create a QApplication instance?

    BTW, actually there has been a plugin based on QtWidget for vlc, it is a gui module, but it dosn't consider that there may have been an instance of QCoreApplication or its subclass, it just instantiate QApplication directly. Is this dangerous?

    JKSHJ 1 Reply Last reply
    0
    • Y yr.zh

      There are some programs have ability to load and unload modules dynamically at runtime, but not using Qt framework(such us vlc). The "plugins" imply these modules.
      If I want to provide a image-related plugin, can I use QtGUI (QImage) to implement it? As the documentation said, there should be a QGuiApplication instance. The questions are, where should it be instantiated and who maitain it?

      For any GUI application using Qt, there is precisely one QGuiApplication object no matter whether the application has 0, 1, 2 or more windows at any given time. For non-GUI Qt applications, use QCoreApplication instead, as it does not depend on the Qt GUI module. For QWidget based Qt applications, use QApplication instead, as it provides some functionality needed for creating QWidget instances.
      

      Consider the following cases:
      case 1:
      If there are two plugins called PA and PB, they both rely on QGuiApplication, PA is loaded before PB. At PA's initialization, PA attemp to get an instance of application with QCoreApplication::instance(), and get a NULL, then PA instantiate a QGuiApplication. There is an instance and PB will be loaded. PB can't create an another QGuiApplication instance, but it can obtain the exist one. Now, PA finish its work and is about to be unloaded. Should PA destroy the instance of QGuiApplication while PB is still using it?
      case 2:
      PA is a plugin rely on QtGui, PB is a plugin rely on QtWighet. PA is loaded before PB, PA create a QGuiApplication at its initialization, how can PB create a QApplication instance?

      BTW, actually there has been a plugin based on QtWidget for vlc, it is a gui module, but it dosn't consider that there may have been an instance of QCoreApplication or its subclass, it just instantiate QApplication directly. Is this dangerous?

      JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by
      #2

      @yr.zh said in Can I use Qt in plugins?:

      If I want to provide a image-related plugin, can I use QtGUI (QImage) to implement it?

      Yes.

      Which classes do you plan to use? I know that QPixmap definitely needs a QGuiApplication instance, but there's a chance that QImage might not. (I'm not 100% sure, so do check and report back)

      As the documentation said, there should be a QGuiApplication instance. The questions are, where should it be instantiated and who maitain it?

      These are design decisions that you need to make.

      Consider the following cases:
      case 1:
      If there are two plugins called PA and PB, they both rely on QGuiApplication, PA is loaded before PB. At PA's initialization, PA attemp to get an instance of application with QCoreApplication::instance(), and get a NULL, then PA instantiate a QGuiApplication. There is an instance and PB will be loaded. PB can't create an another QGuiApplication instance, but it can obtain the exist one. Now, PA finish its work and is about to be unloaded. Should PA destroy the instance of QGuiApplication while PB is still using it?

      If PA destroys the QGuiApplication, then PB will stop working.

      case 2:
      PA is a plugin rely on QtGui, PB is a plugin rely on QtWighet. PA is loaded before PB, PA create a QGuiApplication at its initialization, how can PB create a QApplication instance?

      If PA has already created a QGuiApplication, then PB cannot create a QApplication in the same process.

      NOTE: If PA creates a QApplication, then PB can use that instance. However, PB must make sure its code (especially widget functions) runs in PA's thread!

      BTW, actually there has been a plugin based on QtWidget for vlc, it is a gui module, but it dosn't consider that there may have been an instance of QCoreApplication or its subclass, it just instantiate QApplication directly. Is this dangerous?

      I wouldn't call it dangerous, but it means this plugin is incompatible with other Qt-based plugins.

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      1 Reply Last reply
      1
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

        @JKSH QImage can be used with QCoreApplication.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        1

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved