Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Plugins] Asynchronous drawing #1690

Open
Fabien-B opened this issue Sep 10, 2023 · 1 comment
Open

[Plugins] Asynchronous drawing #1690

Fabien-B opened this issue Sep 10, 2023 · 1 comment
Labels
feature request A request for new functionality or behavior

Comments

@Fabien-B
Copy link

Hello,
Is it possible, or could it be possible in the future to allow plugins to draw asynchronously ?

Consider this code as a minimal example:

void LC_myPlugin::execComm(Document_Interface *doc, QWidget *parent, QString cmd) {
    QTimer* timer = new QTimer(this);
    timer->setSingleShot(true);

    connect(timer, &QTimer::timeout, this, [=]() {
        qDebug() << "timer expired!";
        QPointF start(0,0);
        QPointF end(100, 200);
        doc->addLine(&start, &end);
    });

    timer->start(1000);
}

It crashes with a segfault because the doc pointer is a local variable in the calling method: https://github.com/LibreCAD/LibreCAD/blob/master/librecad/src/main/qc_applicationwindow.cpp#L724-L737

I would like to be able to access to all drawing methods from within the Qt event loop.

This minimal example demonstrate it with a timer, but the drawing could be triggered by any Qt signal.

@dxli
Copy link
Member

dxli commented Sep 13, 2023

The easiest could be adding an interface to accept a smart pointer of doc,

void LC_myPlugin::execComm(std::unique_ptr<Document_Interface> doc, QWidget *parent, QString cmd) {
// move the ownership to the current LC_myPlugin instance
this->m_doc = std::move(doc);
....
connect(timer, &QTimer::timeout, this, [this]() {
        qDebug() << "timer expired!";
        QPointF start(0,0);
        QPointF end(100, 200);
        m_doc->addLine(&start, &end);
    });
....
}

@dxli dxli added the feature request A request for new functionality or behavior label May 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request A request for new functionality or behavior
Projects
None yet
Development

No branches or pull requests

2 participants