Results 1 to 6 of 6

Thread: not a class, namespace, or enumeration??

  1. #1
    Join Date
    Feb 2019
    Posts
    3
    Thanks
    3
    Qt products
    Qt3 Qt4 Qt5

    Question not a class, namespace, or enumeration??

    So I have a class defined in a header file like so...

    Qt Code:
    1. #ifndef TIMER_H
    2. #define TIMER_H
    3. #include <QObject>
    4. class Timer : public QObject
    5. {
    6. Q_OBJECT
    7. public slots:
    8. void StartTimer();
    9. signals:
    10. void TimeOut();
    11. };
    12. #endif // TIMER_H
    To copy to clipboard, switch view to plain text mode 


    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

    Qt Code:
    1. #include "window.h"
    2. #include <QApplication>
    3. #include "timer.h"
    4. int main(int argc, char *argv[])
    5. {
    6. QApplication a(argc, argv);
    7. window w;
    8. Timer t;
    9. t::connect(w, SIGNAL(w::on_textEdit_textChanged()),t,SLOT(t::StartTimer()));
    10. w.show();
    11. return a.exec();
    12. }
    To copy to clipboard, switch view to plain text mode 


    So can anyone explain why I get the error message "'t' is not a class, namespace or enumeration"?
    Last edited by anda_skoa; 26th February 2019 at 07:23. Reason: changed [qtclass] to [code]

  2. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,437
    Thanked 268 Times in 263 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: not a class, namespace, or enumeration??

    t is an object name. Connect should look like :
    Qt Code:
    1. QObject::connect(&w,SIGNAL(on_textEdit_textChanged()),&t,SLOT(StartTimer()));
    To copy to clipboard, switch view to plain text mode 
    .

  3. The following user says thank you to Lesiok for this useful post:

    splashfreeze (26th February 2019)

  4. #3
    Join Date
    Feb 2019
    Posts
    3
    Thanks
    3
    Qt products
    Qt3 Qt4 Qt5

    Default Re: not a class, namespace, or enumeration??

    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.


    HELP.jpg


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

    Qt Code:
    1. #include "window.h"
    2. #include "ui_window.h"
    3. #include <QElapsedTimer>
    4. #include <QTimer>
    5.  
    6. window::window(QWidget *parent) :
    7. QMainWindow(parent),
    8. ui(new Ui::window)
    9. {
    10. ui->setupUi(this);
    11.  
    12. }
    13. window::~window()
    14. {
    15. delete ui;
    16. }
    17. void window::on_textEdit_textChanged()
    18. {
    19. qDebug()<<"\nDEBUGGING";
    20. }
    21. void window::on_label_windowIconTextChanged()
    22. {
    23. qDebug()<<"\nHEEEELP!";
    24. }
    To copy to clipboard, switch view to plain text mode 


    timer.cpp

    Qt Code:
    1. #include "timer.h"
    2. #include <QtDebug>
    3. #include <QElapsedTimer>
    4.  
    5. void Timer::StartTimer()
    6. {
    7. qDebug()<<"Starting the timer!";
    8. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by anda_skoa; 26th February 2019 at 18:53. Reason: changed [qtclass] to [code]

  5. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    3,975
    Thanks
    232
    Thanked 627 Times in 617 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: not a class, namespace, or enumeration??

    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.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  6. The following user says thank you to d_stranz for this useful post:

    splashfreeze (26th February 2019)

  7. #5
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,292
    Thanks
    36
    Thanked 1,521 Times in 1,472 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: not a class, namespace, or enumeration??

    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,
    _

  8. The following user says thank you to anda_skoa for this useful post:

    splashfreeze (26th February 2019)

  9. #6
    Join Date
    Feb 2019
    Posts
    3
    Thanks
    3
    Qt products
    Qt3 Qt4 Qt5

    Default Re: not a class, namespace, or enumeration??

    Ok. Sorry about the screenshot and thank you all for the help. For now my problem has been solved.

Similar Threads

  1. Access QML enumeration from C++
    By sedi in forum Qt Quick
    Replies: 3
    Last Post: 15th April 2016, 10:29
  2. How to use slots in the namespace class
    By gunturrohith in forum Newbie
    Replies: 6
    Last Post: 7th December 2015, 19:20
  3. How to avoid "class namespace" repetition?
    By arcull in forum General Programming
    Replies: 13
    Last Post: 3rd July 2015, 07:07
  4. Replies: 0
    Last Post: 3rd July 2014, 16:48
  5. Replies: 1
    Last Post: 13th September 2006, 12:14

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.