Marco Cuccagna
Marco Cuccagna

Reputation: 105

build a gui with qt for an opencv program

i've developed an opencv program, i take some folder path from input so i decided to create a gui with qt. The gui is simple, basically it's some button. The problem is that i cannot pass the string from a button to another.

std::string MainWindow::on_pushButton_3_clicked()
{
    QString salvataggi=QFileDialog::getExistingDirectory(
                this,
                tr("Open File"),
                "/home/"
                );
    salvat= salvataggi.toStdString();
    return salvat;
}

I tried to use the pointers but without any resoult.

std::string MainWindow::on_pushButton_3_clicked()
{
    QString salvataggi=QFileDialog::getExistingDirectory(
                this,
                tr("Open File"),
                "/home/"
                );
    savee= &salvat;
    *savee = salvataggi.toStdString();
    return savee;
}

can you tell where i'm wrong? Thanks

Upvotes: 2

Views: 135

Answers (1)

Boiethios
Boiethios

Reputation: 42869

This method is a callback and must return void. It is called from the main loop, handled by the Qt engine; and it does not care about the return of the callback.

If you want to store some string from the callback methods, just add some member variable in your MainWindow class :

class MainWindow : public QMainWindow
{
    // ...
    std::string my_string;
    //...
};

And give it the value you want from your callback.

If you only want this info from the user, quit the window: this->close(); and then get the string from the MainWindow object :

int main(int argc, char *argv[])
{
    Application a(argc, argv);
    MainWindow win;
    win.show();
    a.exec();
    /* do what you want with win.my_string */
    //...
}

Upvotes: 1

Related Questions