PDA

View Full Version : not a class, namespace, or enumeration??



splashfreeze
26th February 2019, 02:46
So I have a class defined in a header file like so...



#ifndef TIMER_H
#define TIMER_H
#include <QObject>
class Timer : public QObject
{
Q_OBJECT
public slots:
void StartTimer();
signals:
void TimeOut();
};
#endif // TIMER_H



and what my main function does is simply create an instance of the timer class and make a connect with a signal from
a textedit object

Below is the main function




#include "window.h"
#include <QApplication>
#include "timer.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
window w;
Timer t;
t::connect(w, SIGNAL(w::on_textEdit_textChanged()),t,SLOT(t::Sta rtTimer()));
w.show();
return a.exec();
}



So can anyone explain why I get the error message "'t' is not a class, namespace or enumeration"?

Lesiok
26th February 2019, 07:06
t is an object name. Connect should look like :
QObject::connect(&w,SIGNAL(on_textEdit_textChanged()),&t,SLOT(StartTimer()));.

splashfreeze
26th February 2019, 13:54
So I tried that and the reason why I had not done that was because I thought QObject was just a placeholder name for the actual object. My bad. However, the code still doesn't work. I still have lots of errors.


13032


Also, I forgot to include the code for window.cpp and the timer.cpp. Here they are below...
window.cpp



#include "window.h"
#include "ui_window.h"
#include <QElapsedTimer>
#include <QTimer>

window::window(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::window)
{
ui->setupUi(this);

}
window::~window()
{
delete ui;
}
void window::on_textEdit_textChanged()
{
qDebug()<<"\nDEBUGGING";
}
void window::on_label_windowIconTextChanged()
{
qDebug()<<"\nHEEEELP!";
}



timer.cpp



#include "timer.h"
#include <QtDebug>
#include <QElapsedTimer>

void Timer::StartTimer()
{
qDebug()<<"Starting the timer!";
}

d_stranz
26th February 2019, 18:51
Please don't post screenshots of error messages, copy the actual text and post that. By and large, screenshots are mostly illegible and of little help if you can't read them. And use CODE tags (see below) when posting source code.

From what I can read, it looks as though your project is not compiling the "moc" file produced when the MOC compiler processes the Timer.h header file. As a result, the symbols defined in that file are not being linked into the executable. Try manually running qmake (from the Qt Creator "Build" menu), then rebuild all.

anda_skoa
26th February 2019, 18:56
As d_stranz said this looks like "missing moc run". Also check that your class declaration contains the Q_OBJECT marker.

Aside from that, your original connect doesn't make any sense given the new code you posted.
You are trying to connect a slot to a slot.

Cheers,
_

splashfreeze
26th February 2019, 19:24
Ok. Sorry about the screenshot and thank you all for the help. For now my problem has been solved.