Private slots issue [solved]
-
Hi,
just to be sure: The class to which you added the private slots inherits from QObject (maybe indirectly) and has the Q_OBJECT macro?!? I mean the class itself, not only its parents?!?
I admit, the compiler errors don't really fit. But I wouldn't exclude the possibility that in a special situation these compiler error still occur. And it would be kind of the typical solution when you encounter problems as soon as you add signals and/or slots to your class.
Best Soraltan
-
Hi
Yes, I do have the following
@
class finddialog : public QDialog
{
Q_OBJECT
...
@ -
"Here":https://github.com/mutse/qt5-book-code you can find examples for this book written on Qt5
-
Hmm, odd.
Ok, do this:
Open Qt Creator
Select File -> New File or Project... -> Applications -> Qt Widgets Application (and then keep the default settings)
Select Build -> Run
What do you get?
-
Hi JKSH
It runs fine. Simply a blank form :)
-
Hi Soraltan
Here are the complete code:
find.pro:
@
#-------------------------------------------------Project created by QtCreator 2014-04-30T23:08:06
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = find
TEMPLATE = appSOURCES += main.cpp
finddialog.cppHEADERS += finddialog.h
FORMS += finddialog.ui
@
finddialog.h:
@
#ifndef FINDDIALOG_H
#define FINDDIALOG_H#include <QDialog>
#include <QLabel>
#include <QPushButton>
#include <QLineEdit>
#include <QCheckBox>
#include <QWidget>
#include <QHBoxLayout>namespace Ui {
class finddialog;
}class finddialog : public QDialog
{
Q_OBJECTpublic:
explicit finddialog(QWidget *parent = 0);
~finddialog();
signals:
void findNext(const QString &str,Qt::CaseSensitivity cs);
void findPrevious(const QString & str,Qt::CaseSensitivity cs) ;
private slots:void findClicked();
void enableFindButton(const QString &text);
private:
Ui::finddialog *ui;
QLabel label;
QLineEdit lineEdit;
QCheckBox caseCheckBox;
QCheckBox backwardCheckBox;
QPushButton *findButton;
QPushButton *closeButton;
QHBoxLayout *HLayout;};
#endif // FINDDIALOG_H
@
finddialog.cpp:
@
#include "finddialog.h"
#include "ui_finddialog.h"finddialog::finddialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::finddialog)
{ui->setupUi(this);
}
finddialog::~finddialog()
{
delete ui;
}@
and main.cpp:
@
#include "finddialog.h"
#include <QApplication>int main(int argc, char *argv[])
{
QApplication a(argc, argv);
finddialog w;
w.show();return a.exec();
}@
Do these help?
Thanks
-
Hi,
so looking at your code, here seem to be two private slots declared in the .h. Wehn you remove these the code compiles, when you add these the compiler complains, right?
But there seems to be no definition in the .cpp file! This is probably what the linker complains about.
Add a (even empty) definition for those in the .cpp file should help E.g.
@
void finddialog::findClicked(){
}void finddialog::enableFindButton(const QString &text){
}
@
Does that solve it?!?Best Soraltan
-
Hi Soraltan
That fixed the issue. It's coming from my habit to run/compile as soon as I write one function. I did continue when I got the error ;)
Thank you
P.S. You will be my point of contact for future. I had asked this question in many places even on Faceboook. People tried really hard to help me but you got it right :)