<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Call destructor: QObject and QWidget]]></title><description><![CDATA[<p dir="auto">I'm developing a shared library that contains a window GUI. This library will be loaded dynamically by a main application.</p>
<p dir="auto">To load this shared library in my main application, I'm using <code>QPluginLoader</code>.</p>
<pre><code>void job_manager::test_plugins(QStringList plugins)
{
    foreach(QString file, plugins) {
        qInfo() &lt;&lt; "Loading: " &lt;&lt; file;

        QPluginLoader loader(file);
        if(loader.load())
        {
            qInfo() &lt;&lt; "Loaded: " &lt;&lt; loader.fileName();
            Plugin_API* plugin = qobject_cast&lt;Plugin_API*&gt;(loader.instance());

            if(plugin) {
                qInfo() &lt;&lt; "Plugin Name: " &lt;&lt; plugin-&gt;get_name();
                plugin_map.insert(plugin-&gt;get_name(), plugin);
            } else {
                qInfo() &lt;&lt; "Wrong Plugin API! Could not cast: " &lt;&lt; loader.fileName();
            }
        } else {
            qInfo() &lt;&lt; "ERROR: " &lt;&lt; loader.fileName() &lt;&lt; " - Msg: " &lt;&lt; loader.errorString();
        }
    }
}
</code></pre>
<p dir="auto">Now I can call the loaded plugins any time in my main application. It works!</p>
<p dir="auto">My problem is when the user hits the main application "close button" <strong>BEFORE</strong> close the plugin window.<br />
When this occours, the main application GUI closes Ok, but the plugin GUI window still visible and running.<br />
The main application is not calling the plugin destructor because I don't know how to pass the "parent" pointer to the plugin GUI window method:</p>
<pre><code>void plugin::run()
{
    form = new Form(); // 
    form-&gt;show();
}
</code></pre>
<p dir="auto">I know that the <strong>correct way</strong> to to this is passing the "parent" argument, like:</p>
<pre><code>void Analysis_x::run()
{
    // Compile error because my Plugin is a QObject type and the argument MUST be QWidget type 
    form = new Form(this); 
    form-&gt;show();
}
</code></pre>
<p dir="auto"><strong>My plugin header is:</strong></p>
<pre><code>class ANALYSIS_XSHARED_EXPORT Analysis_x: public QObject, public Plugin_API
{
    Q_OBJECT
    Q_PLUGIN_METADATA(IID "com.lamar.plugin")
    Q_INTERFACES(Plugin_API)

public:
    explicit Analysis_x(QObject* parent = nullptr);
    ~Analysis_x() override;

    QString get_name(void) override;
    QString get_description(void) override;
    QJsonObject get_input_variables(void) override;
    QJsonObject get_output_variables(void) override;
    QString get_output_name(int output) override;
    void set_save_output(int output, bool save) override;
    void set_working_data_file(QString data_path) override;
    void set_working_log_file(QString log_path) override;
    void run(void) override;
    void set_console_output(bool enabled) override;

private:
    Form* form;

signals:
public slots:
};
</code></pre>
<p dir="auto">I would like to, when the user hits the main application "close button", the main application close the plugin window GUI automatically.</p>
<p dir="auto"><strong>So, how can I pass a valid "parent" argument (QWidget) to the Form?</strong></p>
<p dir="auto">You can saw a close example of this problem in this YouTube tutorial video in the 10:00 minutes:<br />
[<a href="https://www.youtube.com/watch?v=VigUMAfE2q4" target="_blank" rel="noopener noreferrer nofollow ugc">https://www.youtube.com/watch?v=VigUMAfE2q4</a>](link url)</p>
]]></description><link>https://forum.qt.io/topic/106195/call-destructor-qobject-and-qwidget</link><generator>RSS for Node</generator><lastBuildDate>Sat, 17 Oct 2026 12:24:18 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/106195.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 23 Aug 2019 20:26:01 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Call destructor: QObject and QWidget on Fri, 23 Aug 2019 20:35:35 GMT]]></title><description><![CDATA[<p dir="auto">Hi<br />
Just add a function in Plugin_API that takes a QWidget * that your<br />
internal forms can use as parent. (you store it in plugin)</p>
]]></description><link>https://forum.qt.io/post/547585</link><guid isPermaLink="true">https://forum.qt.io/post/547585</guid><dc:creator><![CDATA[mrjj]]></dc:creator><pubDate>Fri, 23 Aug 2019 20:35:35 GMT</pubDate></item></channel></rss>