Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Some functions werent declared problem
Qt 6.11 is out! See what's new in the release blog

Some functions werent declared problem

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 4.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kingsta
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • Q Offline
      Q Offline
      qxoz
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • K Offline
        K Offline
        kingsta
        wrote on last edited by
        #3

        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?

        1 Reply Last reply
        0
        • Q Offline
          Q Offline
          qxoz
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          • U Offline
            U Offline
            utcenter
            wrote on last edited by
            #5

            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...

            1 Reply Last reply
            0
            • K Offline
              K Offline
              kingsta
              wrote on last edited by
              #6

              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?

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved