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. Cannot find .moc files - QObject Error?
Forum Updated to NodeBB v4.3 + New Features

Cannot find .moc files - QObject Error?

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 2 Posters 2.9k 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.
  • M Offline
    M Offline
    mjv817
    wrote on last edited by
    #1

    Hey guys, new to QT development and have been going through some example code. When I try to compile the code I receive an error msg about missing .moc files.

    Currently on windows 10, using the QT Creator IDE. I Have a main.cpp file, header file, and definition file.

    .pro file

    /QT       += core gui
    
    CONFIG += c++11
    
    TARGET = NewGUI
    
    TEMPLATE = app
    
    SOURCES += \
        hello.cpp
        finddialog.cpp
    
    
    
    HEADERS += \
        finddialog.h
    
    /
    

    .header file

    /#ifndef FINDDIALOG_H
    #define FINDDIALOG_H
    #include <QDialog>
    
    class QCheckBox;
    class QLabel;
    class QLineEdit;
    class QPushButton;
    
    
    class FindDialog : public QDialog
    {
        Q_OBJECT
    public:
        FindDialog(QWidget *parent = 0);
    signals:
        void findNext(const QString &str, Qt::CaseSensitivity cs);
        void findPrev(const QString &str, Qt::CaseSensitivity cs);
    
    private slots:
        void findClicked();
        void enableFindButton(const QString &text);
    private:
        QLabel *label;
        QLineEdit *lineEdit;
        QCheckBox *caseCheckBox;
        QCheckBox *backwardCheckBox;
        QPushButton *findButton;
        QPushButton *closeButton;
    };
    
    #endif // FINDDIALOG_H
    
    /
    

    finddialog.cpp

    /#include <QtGui>
    #include "finddialog.h"
    
    
    FindDialog::FindDialog(QWidget *parent) : QDialog(parent)
    {
        label = new QLabel(tr("Find &what:"));
        lineEdit = new QLineEdit;
        label->setBuddy(lineEdit);
    
        caseCheckBox = new QCheckBox(tr("Match &case"));
        backwardCheckBox = newQCheckBox(tr("Search &backward"));
    
    
        findButton = new QPushButton(tr("&Find"));
        findButton->setDefault(true);
    
        findButton->setEnabled(false);
        closeButton = new QPushButton(tr("Close"));
    
        connect(lineEdit,SIGNAL(textChanged(const QString &)), this, SLOT(enableFindButton(const QString &)));
    
        connect(findButton, SIGNAL(clicked()),this, SLOT(findClicked()));
    
        connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));
    
    
        QHBoxLayout *topLeftLayout = new QHBoxLayout;
        topLeftLayout->addWidget(label);
        topLeftLayout->addWidget(lineEdit);
    
    
        QVBoxLayout *leftLayout = new QVBoxLayout;
        leftLayout->addLayout(topLeftLayout);
        leftLayout->addWidget(caseCheckBox);
        leftLayout->addWidget(backwardCheckBox);
    
        QVBoxLayout *rightLayout = new QVBoxLayout;
        rightLayout->addWidget(findButton);
        rightLayout->addWidget(closeButton);
        rightLayout->addStretch();
    
        QHBoxLayout *mainLayout = new QHBoxLayout;
        mainLayout->addLayout(leftLayout);
        mainLayout->addLayout(rightLayout);
        setLayout(mainLayout);
    
        setWindowTitle(tr("Find"));
        setFixedHeight(sizeHint().height());
    
    
    
    }
    
    void FindDialog::findClicked()
    {
        QString text = lineEdit->text();
        Qt::CaseSensitivity cs = caseCheckBox->isChecked() ? Qt::CaseSensitive : Qt::CaseInsensitive;
    
        if (backwardCheckBox->isChecked()) {
            emit findPrevious(text, cs);
        }
        else {
            emit findNext(text,cs);
        }
    
    }
    
    void FindDialog::enableFindButton(const QString &text)
    {
        findButton->setEnabled(!text.isEmpty());
    }
    /
    

    main

    /#include <QApplication>
    #include "finddialog.h"
    #include "main.moc"
    int main (int argc, char *argv[])
    {
    
    
    
        QApplication app(argc, argv);
        FindDialog *dialog = new FindDialog;
    
        dialog->show();
        return app.exec();
    
    
        return app.exec();
    
    }
    
    
    
    /
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      Which version of Qt are you using ?

      There's no need for than main.moc include.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      M 1 Reply Last reply
      1
      • SGaistS SGaist

        Hi and welcome to devnet,

        Which version of Qt are you using ?

        There's no need for than main.moc include.

        M Offline
        M Offline
        mjv817
        wrote on last edited by
        #3

        @SGaist

        Running 4.1.0 (Community)

        When I remove the #include main.moc file the compiler generates several linkage errors. The book I am reading through mentions this issue and says to run the qmake file again to fix this problem. From my limited understanding the .moc file generation should happen automatically once I regenerate the make file. Not sure why that is not happening.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          4.1 ? That version is almost 11 years old.

          Since you are starting, please get Qt 5. The current version is 5.7 with 5.8 beta also available.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          1
          • M Offline
            M Offline
            mjv817
            wrote on last edited by mjv817
            #5

            OK went and downloaded the .exe again to reinstall. It appears I am running QT 5.7. I am still having this issue though. So after doing a bit more search I found one error,

            I needed to replace #include<QtGui> with <QtWidgets>.

            Now I am receiving two errors for the same problem. "identifier not found" in my finddialog file.

            Edit

            Figured out the rest of my errors. Had a misspelled variable. Got it working now.

            Thanks!

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Great !

              Since you have it working now, please mark the thread as solved using the "Topic Tools" button so that other forum users may know a solution have been found :)

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              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