mercredi 19 juillet 2017

app crashes when I try to get text value from QLineEdit

I'm building a simple desktop application for a school project. I'm using Qt creator. The code down here has the purpose to edit infos of a determinate class, I have a QPlainText widget called "titolo" where I can edit the text contained in it, so when I click on the QButton "bOk" I can edit the info directly in the class members.

The problem is that it was all going ok until some point, the code was working while all of a sudden the application started crashing while giving me error 255. I've tried to debug and I think that the problem is in the edit() function, when I try to get the text value from titolo which is a QLineEdit widget.

void View_Publications :: buildPubEditView(){
layout = new QGridLayout(this);

    //EDIT TITOLO
QLabel* tit = new QLabel("Titolo: ");

QLineEdit* titolo = new QLineEdit();
titolo -> setPlaceholderText(QString("Es: L'orso Giovanni"));
titolo -> setText(QString::fromStdString(currentPub->getTitle()));
titolo -> setReadOnly(false);
titolo -> setMaxLength(32);
titolo -> setFixedWidth(300);

layout -> addWidget(tit, 0, 0);
layout -> addWidget(titolo, 1, 0);

       //BUTTONS
QGridLayout* gridButt = new QGridLayout();

QPushButton* bNo = new QPushButton();
bNo -> setText("Annulla");
bNo -> setFixedWidth(70);

QPushButton* bOk = new QPushButton();
bOk -> setText("Conferma");
bOk -> setFixedWidth(70);  

gridButt -> addWidget(bNo, 0, 0);
gridButt -> addWidget(bOk, 0, 1);

layout -> addLayout(gridButt, 5, 0);

connect(bNo, SIGNAL(clicked()), this, SLOT(rejectedits()));

connect(bOk, SIGNAL(clicked()), this, SLOT(checkAndEdit()));   

}

void View_Publications :: checkAndEdit(){
    if(check()){
        edit();
    }
    else{   QMessageBox error;
            error.setWindowTitle("Errore");
            error.setText("Dati errati");


    }
}

bool View_Publications :: check() const{
    if(titolo -> text() == ""){
        QMessageBox error;
        error.setWindowTitle("Errore");               
        error.setText("Non hai inserito nessun titolo");
        error.exec();
        return false;
    }


    return true;
    }

void View_Publications :: edit() const{
    currentPub -> setTitle(titolo -> text().toStdString());
}

If into the edit() function I put currentPub -> setTitle("aaaaa"); All works fine so it's not related to currentPub. Am I doing something wrong? thank you for your answers

Aucun commentaire:

Enregistrer un commentaire