Skip to content
  • Unload Plugin in Qt 4.8

    Unsolved General and Desktop
    7
    0 Votes
    7 Posts
    86 Views
    D

    @SGaist I think it will be easier if I provide a piece of code

    I have 2 app: AppPlugin and MainApp
    In these two app there is a class that stores global variables:

    GlobalData.h

    extern MainWindow *mainWindow;
    extern QWidget *wgt;
    extern QGraphicsScene *scene;
    extern QGraphicsView *view;
    extern QDeclarativeEngine *engine;

    <<<<<<<<
    GlobalData.cpp

    MainWindow *mainWindow;
    QWidget *wgt;
    QGraphicsScene *scene;
    QGraphicsView *view;
    QDeclarativeEngine *engine;

    <<<<<<<<

    AppPlugin:

    int main(…)
    {
    QApplication a(argc, argv);
    mainWindow = new MainWindow;
    return a.exec()(
    }
    <<<<

    MainWindow.h
    class MainWindow : public QObject
    {
    MainWindow(QObject * parent = 0);
    ~MainWindow();
    Q_INVOKABLE unloadPlugin();
    signals:
    Void unloadPluginSignal();
    }
    <<<<
    MainWindow.cpp
    MainWindow::MainWindow(QObject *parent) : QObject(parent)
    {
    wgt = new QWidget;

    scene = new QGraphicsScene(…);

    view = new QGraphicsView(…);

    engine = new QDeclarativeEngine;
    //
    add main.qml on scene
    //
    wgt->show();
    }
    MainWindow::~MainWindow()
    {
    qDebug() << “delete mainModel”;
    }

    void MainWindow::unloadPlugin()
    {
    emit unloadPluginSignal();
    }

    <<<<

    PluginInterface.h

    class PluginInterface : public QObject
    {
    Q_OBJECT
    public:
    virtual ~PluginInterface(){}
    virtual void getEngine(QDeclarativeEngine *extEngine) =0;
    Q_SIGNAL void signalFromPlugin();
    };
    Q_DECLARE_INTERFACE(PluginInterface, “MyTestPlugin”)

    <<<<<
    Plugin.h
    class Plugin : public PluginInterface
    {
    Q_OBJECT
    Q_INTERFACES(PluginInterface)
    public:
    ~Plugin();
    void getEngine();
    public slots:
    void unloadPlugin();
    }
    <<<<<

    Plugin.cpp
    Plugin::~Plugin()
    {
    qDebug << “delete plugin”;
    }

    void Plugin::getEngine()
    {
    //
    may get the engine from the main application, but in principle I don’t need it.
    //
    mainWindow = new MainWindow;
    connect(mainWindow, SIGNAL(unloadPluginSignal()), this, SLOT(unloadPlugin()));
    }
    void Plugin::unloadPlugin()
    {
    emit signalFromPlugin();
    }

    Q_EXPORT_PLUGIN2(PluginInterface, Plugin)

    Then from main.qml I call the slot with MainWindow - unloadPlugin

    main.qml
    Rectangel{

    Rectangel{

    MouseArea{
    anchors.fill: parent
    onClocked: mainWindowContext.unloadPlugin()
    }

    }
    }

    ——-/—/————————
    MainApp:

    Int main(…)
    {
    QApplicatino a(argc, argv);
    mainWindow = new MainWindow;
    return a.exec();
    }

    MainWindow.h

    class MainWindow: public QObject
    {
    Q_OBJECT
    public:
    MainModel();

    Q_INVOKABLE bool loadPlugin();

    public slots:
    void unloadPlugin();

    private:
    PluginInterface *plugin;
    QPluginLoader *loader;
    }

    MainWindow.cpp

    MainWindow::MainWindow()
    {
    wgt = new QWidget;

    scene = new QGraphicsScene(…);

    view = new QGraphicsView(…);

    engine = new QDeclarativeEngine;
    //
    add main.qml on scene
    //
    wgt->show();
    }

    bool MainWindow::loadPlugin()
    {
    loader = new QPluginLoader(//src plugin//);
    If(loader->load())
    {
    If( plugin = qobject_cast<PluginInterface*>(loader->instance()))
    {
    plugin->getEngine(engine);
    connect(plugin, SIGNAL(signalFromPlugin()), this, SLOT(unloadPlugin()));
    return true;
    }
    return false
    }
    }

    bool Plugin::unloadPlugin()
    {
    bool result = loader->unload();
    qDebug() << result;
    }

    after clicking on the button in ManApp and calling the loadPlugin method, it is loaded and displayed, but as soon as I click on the close button of this plugin, the unloadPlugin method is called on me and the result variable will return true, after that the application immediately crashes with segmentationFault

  • 0 Votes
    2 Posts
    13 Views
    sierdzioS

    You are likely behind a router running NAT (Network Address Translation), and also likely your IP address is semi-random (your ISP gives you a new IP address every time your router is restarted or connection drops, etc.). Plus very likely port 12345 is blocked by your router's firewall.

    In order to make this work you need to have some publicly available, static IP address with network configured to allow communication on port 12345. How exactly to do this depends on your circumstances. Maybe you need to rent a server from some server room, or you can get a static IP from your ISP, or you can use some cloud provider like AWS. There are plenty of options to choose from, please read up on it. This is not a Qt-related issue; every service available on the Internet has to go through this.

  • 0 Votes
    1 Posts
    3 Views
    No one has replied
  • 0 Votes
    1 Posts
    5 Views
    No one has replied
  • 0 Votes
    2 Posts
    27 Views
    jeremy_kJ

    @LS-KS said in QAbstractListModel as member of QmlSingleton in Python not working:

    But the app starts with an empty list view. And no error is thrown.

    You might need to turn on the appropriate logging categories.

    a print-statement in the model's data method shows it is never called.

    Are you certain that SignalController.signalModel in the QML is referencing self.signalModel from the Python-defined singleton? In the code posted, I don't see a definition of a Qt property. With PyQt, exposing a Python object member as a property to QML requires a little code:

    class Object(QObect): @pyqtProperty(str) def myProperty(): return "some text" Text { text: Object.myProperty }
  • 0 Votes
    6 Posts
    61 Views
    B

    @qtenjoyer It has nothing to do with QStackedLayout, the stylesheet doesn't work because you set it on a subclassed QWidget.
    You may check the QWidget part of https://doc.qt.io/qt-6/stylesheet-reference.html.

  • How to use "import std" in C++

    Unsolved Language Bindings
    5
    0 Votes
    5 Posts
    71 Views
    SGaistS

    @AltitudeDashboard hi,

    Did you follow the recommendation from @cristian-adam ?

    The article linked also provided a complete example with a CMakeFiles.txt so you could take it and open it with Qt Creator. Please note the minimal CMake version required.

  • 0 Votes
    5 Posts
    78 Views
    M

    @MasterBLB Thanks.

  • 0 Votes
    3 Posts
    40 Views
    A

    @Christian-Ehrlicher said in [Debugger confusion] Debugger encountered an exception: Exception at Ox7ffd94b153ac, code: 0x8001010d:, flags-0x81 (first chance):

    First chance exceptions are normally ok - these are exceptions which are catched inside the program. Is your device properly connected and can you access it with other tools? What exact Qt version do you use? Does Qt supports your device?

    Thank you for your reply. My Qt version is 6.5, I can normally support my device, and the connection is normal, can also transfer data normally, comment out the function QCanBusDevice * CanMainWindow:: GetCanBusDevice const(), the program can run normally. But I still want to understand, why does this anomaly happen?

  • 0 Votes
    3 Posts
    29 Views
    Pl45m4P

    @MasterBLB said in QSlider linked with other QSlider - hints needed:

    And again, soon after I post here I get stroke of genius, and find solution on my own. Happens almost every time.

    Rubber Duck Debugging at its best :))

  • 0 Votes
    5 Posts
    75 Views
    SGaistS

    It should already be there but did you check the library to see if the symbol is available ? I don't see a reason for it not to be there though but at least it will remove a suspect.

  • 0 Votes
    1 Posts
    18 Views
    No one has replied
  • 0 Votes
    12 Posts
    156 Views
    Chris KawaC

    So what should I use? I need to capture a frame every second and perform some operations

    If you need the system to stay awake it should be enough to call this once:
    SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED)
    Alternatively you can start a timer and call this periodically:
    SetThreadExecutionState(ES_SYSTEM_REQUIRED)
    If you also need the display to stay on add ES_DISPLAY_REQUIRED to any of those.

    What should I do in case of failure?

    I don't know. It's your app. You could inform the user, close the app, do nothing or anything else you feel like. Up to you.

  • 0 Votes
    3 Posts
    38 Views
    hskoglundH

    Hi just a guess, but I notice for the VS Studio 2022 compilation you're using the /sdl switch which sets pointers in your classes to nullptr at start (as a debugging help) but I don't see that switch in your Qt .pro file for MSVC 2019.
    Maybe if you try removing the /sdl switch (or adding it to the .pro file) the builds will behave less differently.

  • Qt 5.15.17, any release date prevision?

    Solved Announcements
    6
    0 Votes
    6 Posts
    192 Views
    T

    @BillouParisPro Were you able to get any feedback from Qt about 5.15.17 release date?

  • 0 Votes
    3 Posts
    64 Views
    RokeJulianLockhartR

    @GrecKo, apologies for the wait. Do you know how to ascertain where that is? I ask because I didn't choose a location, so it must have been predetermined.

  • 0 Votes
    4 Posts
    38 Views
    JonBJ

    @FishBoneEK
    We could do with someone who has the Qt Linux code telling us what waitForStarted() actually does/how it defines/detects "started". Like I said, I didn't follow it down on woboq. Then we might have a clue whether/what sddm might do which could apparently cause your "stuck" behaviour.

  • 0 Votes
    9 Posts
    132 Views
    RokeJulianLockhartR

    @Pl45m4 said in I'm struggling to run Qt's C# examples. Please assist.:

    I did that. I've detailed that above. I even linked to them.

    You said, you've "opened the folder" in VS Code... opening a directory is not the same as loading a project/solution file.

    I've included six steps of what I did, and to my knowledge, I loaded it. Is VS Code incapable of that, even with the aforementioned extensions installed?

    @Pl45m4 said in I'm struggling to run Qt's C# examples. Please assist.:

    CLI PowerShell script to having a GUI

    One guy here is the owner of some "Qt Widget CLI" project on GitHub... Which "renders" simple QtWidgets like buttons and so on, in a CLI environment.
    Can't remember who is was actually :(
    @kshegunov you (maybe)?
    @J-Hilk or you?
    @SGaist you know everything :P
    Maybe one of you knows what I'm talking about and can link to that.

    Thank you for that. I suppose a TUI isn't a terrible stopgap in some circumstances.

  • 1 Votes
    14 Posts
    340 Views
    8Observer88

    I have made the next demo for WebAssembly, Android, and Desktop using: Qt C++, OpenGL ES 2.0, OpenAL-Soft (this is a library for music and sounds), Box2D (for jumps, collision detections, and ray casting), Hiero (this is an application to create a font with distance field from TTF), Free Texture Packer (to pack images to one texture atlas), and Tiled map editor (to position sprites and Box2D static colliders).

    Click to run in your browser (it is a link to itch where you can download EXE for Windows 10 64 bit and APK for Android 7-14) Click to run in your browser (it is a link to the Netlify free hosting) GitHub repository

    All resources (sprites, music and sounds) have been replaced with free ones. You can see a list of free resources here. For example, I took the sprites here: https://webfussel.itch.io/more-bit-8-bit-mario

    I have made a custom joystick for Android in pure OpenGL ES 2.0 (this is an animation from the real phone that I made using scrcpy):

    mario-2d-jumps-webfussel-opengles2-qt6-cpp-android.gif

  • 0 Votes
    2 Posts
    26 Views
    Axel SpoerlA

    Hello,
    please provide a minimal compilable reproducer.
    Looks to me as if the reference to the resource file in ToolBar.qml:46:23 is wrong.