0

So I want to call function when I press the button that I created like that: QPushButton *pb = new QPushButton; Function I want to call is :Engine::gauss(QLineEdit *&line, QLineEdit *&results, int sizeMatters). So the problem is I all those arguments are in another slot, in on_button_clicked function to be exact:

   void MainWindow::on_pushButton_clicked()
{
    Result x;
    int sizeMatters;
    sizeMatters=ui->le_size->text().toInt();

    int c = ui->grid->count();
    if(c!=0){
        for(int m = 0; m < c; m++){
            ui->grid->itemAt(m)->widget()->close();
        }

    }

    c = ui->grid_results->count();
    if(c!=0){
        for(int f = 0; f < c; f++){
            ui->grid_results->itemAt(f)->widget()->close();
        }
    }
    ui->le_size->setMaxLength(2);

    QLineEdit *line = new QLineEdit[sizeMatters*sizeMatters];
    QLabel *label = new QLabel[sizeMatters];
    QLineEdit *results = new QLineEdit[sizeMatters];
    QLineEdit *finals = new QLineEdit[sizeMatters];

    int w = 0;
    for(int j = 0; j<sizeMatters; j++){
        for(int i = 0; i<sizeMatters; i++){
            ui->grid->addWidget(&line[w],j+1,i+1);
            w++;

        }
        label[j].setText("=");
        ui->grid->addWidget(&label[j],j+1,sizeMatters+1);
        ui->grid->addWidget(&results[j],j+1,sizeMatters+2);

    }


    for(int j = 0; j<sizeMatters; j++){
        ui->grid_results->addWidget(&finals[j],1,j+1);
    }
    QPushButton *pb = new QPushButton;
    if(c==0){

    ui->verticalLayout->addWidget(pb);
  }



    for(int p=0;p<sizeMatters;p++){
        QString liczba = QString::number(x.wyniki[p]);

        finals[p].setText(liczba);
    }



}

So I want to call gauss function that is in engine.cpp, and is part of Engine class, when clicking "pb" button. How can I achieve that?

  • Is `Engine::gauss` a static method, or do you need some instance of Engine available to call it? – Syntactic Fructose Mar 27 '17 at 05:03
  • Its static "static Result gauss(QLineEdit *&line, QLineEdit *&results, int sizeMatters);" – Mikołaj Popieluch Mar 27 '17 at 05:04
  • just call it in normal button click slot. – Pavan Chandaka Mar 27 '17 at 05:21
  • I can't because I wouldn't have QLineEdit *&line, QLineEdit *&results, int sizeMatters values in that function – Mikołaj Popieluch Mar 27 '17 at 05:22
  • 1
    @MikołajPopieluch Please, have a look at [SO: How to subclass QPushButton so that the signal sends an argument to the slot?](http://stackoverflow.com/questions/43014313/how-to-subclass-qpushbutton-so-that-the-signal-sends-an-argument-to-the-slot/43015250#43015250). I used lambdas for adaptors to solve a similar issue. There is also a link to another (even more encompassing) answer. – Scheff's Cat Mar 27 '17 at 05:33
  • Are you even sure the rest of the code works? it looks like you create lots of arrays of UI elements, but never the UI widgets itself, also a lot of memory leaks in that code. And you pass a pointer to a pointer to the `addWidget` methods, that seems wrong. – xander Mar 27 '17 at 06:25
  • @xander it does work – Mikołaj Popieluch Mar 27 '17 at 06:36

0 Answers0