I'm fairly new at C++/Qt, and I only have some web development experience.
I'm testing a few things with Qt for learning purposes and I'm failing miserably at it. I'm pretty sure it's because the whole slot/signal thing hasn't settled in yet, so I was hoping someone could make it clearer for me.
So, I have this main program UI where I have placed a QTextEdit widget. Now I'm trying to reproduce one of those "there are changes to the document, better save it!"-warnings, and it's being displayed everytime someone tries to create a new document.
I'm trying to test for changes in the textEdit widget when the "New Document" option is triggered. I keep getting these compile errors and I don't even know what they mean! What would be the correct test condition? How can I refer to the textEdit, since it's being called somewhere else?
I'm trying something like this:
void Notepad::on_actionNew_triggered() { //not getting the test condition right! if(................................) { QMessageBox msgBox; msgBox.setText("Warning!"); msgBox.setInformativeText("Changes were applied to this document."); msgBox.setStandardButtons(QMessageBox::Discard | QMessageBox::Cancel); msgBox.setDefaultButton(QMessageBox::Cancel); int ret = msgBox.exec(); switch (ret) { case QMessageBox::Discard: // Don't Save was clicked ui->textEdit->clear(); break; case QMessageBox::Cancel: msgBox.close(); break; default: // should never be reached break; } }else{ui->textEdit->clear();} }
I have tried searching some information about this, and I bet most of you might actually think this is pretty obvious, but I'm having real trouble understanding how to get around this.