Solved Cannot find .moc files - QObject Error?
-
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(); } /
-
Hi and welcome to devnet,
Which version of Qt are you using ?
There's no need for than
main.moc
include. -
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.
-
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.
-
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!
-
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 :)