Important: Please read the Qt Code of Conduct -

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) :

    QTextEdit *textEdit = new QTextEdit;
    QPushButton *quitButton = new QPushButton("&Quit");
    QObject::connect(quitButton, SIGNAL(clicked()),qApp, SLOT(quit()));
    QVBoxLayout *layout = new QVBoxLayout;


    void Notepad::quit(){
    QMessageBox messageBox;
    messageBox.setText(tr("Do you really want to quit?"));
    messageBox.setStandartButtons(QMessageBox::Yes | QMessageBox::No);

     if(messagebox.exec() == QMessageBox::Yes)


    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 "": this point or use some book about Qt programming.

  • I try to do "that": tutorial. I use Qt 4.8. Do you think I use Qt 5.0?

  • Nice example. If you write exactly as in tutorial it should work, and pay attention to the doc note from Volker on bottom .
    Change QObject to QWidget and check is all includes are present.

  • Well, this tutorial doesn't seem to include deriving from QObject.

    Then again, the constructor code doesn't initialize neither a QObject nor a QWidget...

  • 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?

Log in to reply