c++ - How to pass parameters between Windows in Qt?

Asked

Viewed 654 times

0

Hi, I’m trying to pass a mat parameter from one window to another, being activated by the click of a button. The program compiles and runs normally, but when clicking the button that activates the event, the program gives a chrash on the execution. Below the code snippet that calls to another window:

void MainWindow::on_commandLinkButton_clicked(){

    Form *form = new Form();
    form->setInput(this->ModFirstP);
    form->execTransform();
    form->setLabels();
    form->show();

}

The problematic parameter is Modfirstp of type Mat, I want to set it in an attribute of the other window I am generating:

.H

void setInput(Mat&);

.cpp

void Form::setInput(Mat& in){
    this->input = in;
}

Would anyone know how to pass parameters between Windows (Forms) in Qt? Or does Qt only accept Qobject objects as parameters between windows? Thanks in advance.

  • Yuri, I don’t have Qt installed but if I’m not too crazy the framework does not contain any Form classes (until you clone them with a Q). Is this Form class implemented by extending some Qt class? I believe that the standard Qt classes (Qwidget, Qdialog, Qmainwindow) do not contain a setInput method until I found nothing about it in the online documentation.

  • This form was another window I created using the Qt Creator IDE itself, it extends from Qwidgets, the setInput method I created to set the Mat Modfirstp attribute. Thank you for the reply.

  • Yuri, now yes your question has become clearer to me. The way you are doing is correct. It remains to be seen whether the pointer passed to the other window points to a valid memory location (this may be what causes the crash). If you can also post the code that accesses this pointer in "Form" maybe I can help you more specifically.

  • After several hours of cracking my head I figured out what the problem was, you’re right @Brunobermann the statement is really right, I thought the crash problem was in the statement between the Forms, but after a while I realized I had accidentally deleted a line from my window class. I will reformulate the resolution in a reply to the post. Thank you.

  • Glad you could make it, glad to help.

1 answer

1

Well, after hours and hours of cracking my head on what would be causing the application crash, I discovered that the problem was with the ui->setupUi(this) line; where I had accidentally deleted the constructor from my new window class. After including this line, the code worked normally, and the problem was not in passing parameters as I had imagined. It seems to me that this line that I deleted triggers any kind of interaction and manipulation with my class from my second window, so the program compiled normally, but could not access the class data. Well, anyway, thanks for the answers and attention.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.