Some functions werent declared problem
-
Hi guys.
I have a little problem. I am a new one. I want to do basic tutorial in Qt.
@Notepad::Notepad(QObject *parent) :
QObject(parent)
{QTextEdit *textEdit = new QTextEdit; QPushButton *quitButton = new QPushButton("&Quit"); QObject::connect(quitButton, SIGNAL(clicked()),qApp, SLOT(quit())); QVBoxLayout *layout = new QVBoxLayout; layout->addWidget(textEdit); layout->addWidget(quitButton); setLayout(layout); setWindowTitle(tr("Notepad"));
}
void Notepad::quit(){
QMessageBox messageBox;
messageBox.setWindowTitle(tr("Notepad"));
messageBox.setText(tr("Do you really want to quit?"));
messageBox.setStandartButtons(QMessageBox::Yes | QMessageBox::No);
messageBox.setDefaultButton(QMessageBox::No);if(messagebox.exec() == QMessageBox::Yes) qApp->quit();
}@
I got "setLayout, setWindowTitle, messageBox was not declared in this scope" error.
I got "Class MessageBox has no member named setStandartButtons" error.I guess I didnt include some library. How can i fix them?
-
First of all what basic tutorial you use?
Your Notepad class inherits QObject but you call functions which belongs to QWidget.
Try start from "http://qt-project.org/doc/qt-5.0/qtdoc/index.html":http://qt-project.org/doc/qt-5.0/qtdoc/index.html this point or use some book about Qt programming. -
I try to do "that":http://qt-project.org/doc/qt-4.8/gettingstartedqt.html tutorial. I use Qt 4.8. Do you think I use Qt 5.0?
-
You right example has a bug.
I found the caouse of error. I try to make a little different class like QDialog. I have MainWindow class and NotePad class. I wrote those codes in NotePad class. When i write those codes in MainWindow class, I have no problem. setLayout() and setWindowTitle() are work well in MainWindow class.
I realize If I declare a new class in QDialog, there is no problem but i cant declare in QObject. New class is NotePad in my question. How can i use setLayout() and setWindowTitle() functions in another class?