Results 1 to 7 of 7

Thread: Problems with the Q_OBJECT-Macro

  1. #1
    Join Date
    Mar 2009
    Location
    Europe
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Problems with the Q_OBJECT-Macro

    Hello out there,
    I have so troubble building a small app. My main.cpp has this easy structur:
    #include "qtexplorer.h"

    #include <QtGui>
    #include <QApplication>
    #include <QPushButton>

    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);
    QtExplorer w = new QtExplorer;
    w.show();
    return a.exec();
    }

    my QtExplorer.h looks like this:
    #ifndef QTEXPLORER_H
    #define QTEXPLORER_H

    #include <QWidget>
    #include <QPushButton>
    #include <QVBoxLayout>
    #include "ui_qtexplorer.h"

    class QtExplorer : public QWidget
    {
    Q_OBJECT

    public:
    QtExplorer(QWidget *parent = 0);
    ~QtExplorer();

    private:
    Ui::QtExplorerClass ui;
    long req_id;
    private slots:
    int ReadRegister();
    int WriteRegister();
    int ReadMem();
    int WriteMem();
    };

    #endif // QTEXPLORER_H


    So, what is my problem? I cannot build this easy code because there is an error at the first curly brace in the qtexplorer.h (this comes of the eclipse integration plugin) which says: "within this context".
    After that brace comes the macro Q_OBJECT. Without this macro I cannot define slots. But what can I do to clear this error?

    Thank you in advance..

    Sincerely Tok

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Problems with the Q_OBJECT-Macro

    what the strange code
    Qt Code:
    1. ...
    2. QtExplorer w = new QtExplorer;
    3. w.show();
    4. ...
    To copy to clipboard, switch view to plain text mode 

    modify it
    Qt Code:
    1. ...
    2. QtExplorer w;
    3. w.show();
    4. ...
    To copy to clipboard, switch view to plain text mode 
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. #3
    Join Date
    Mar 2009
    Location
    Europe
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Problems with the Q_OBJECT-Macro

    Thanks now it works. But what is the difference? Why I cannot call it by the usual methode?

    Sincerely Tok

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Problems with the Q_OBJECT-Macro

    Qt Code:
    1. QtExplorer *w = new QtExplorer();
    2. w->show();
    3. delete w;
    To copy to clipboard, switch view to plain text mode 

    or

    Qt Code:
    1. QtExplorer w;
    2. w.show();
    To copy to clipboard, switch view to plain text mode 

    Once you create the object on the heap, once on the stack.
    Qt Code:
    1. QtExplorer w = new QtExplorer();
    To copy to clipboard, switch view to plain text mode 
    is just invalid code...

  5. #5
    Join Date
    Mar 2009
    Location
    Europe
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Problems with the Q_OBJECT-Macro

    Okay thank you.
    The reason why I changed it to a new()-constructor is, that I cannot debug the small program. If I start the debugger (under Eclipse Qt-integration, Linux) I get the message "No symbol "new" in current context." on the eclipse-console. I thought this isn't serious but I tied with a new()-operator.
    I start debugging with the main-method (obvious) but if I jump to the construction point ( QtExplorer w; ) the sourcecode-window is closed with a message "No source available for "" " and if I go one step further, the whole execution stops with the message "Cannot find bounds of current function".

    What is the meaning of that? (I installed the libqt-dbg!)

    Thank you in advance

    Sincerely Tok
    Last edited by tokstolle; 23rd March 2009 at 16:45.

  6. #6
    Join Date
    Mar 2009
    Location
    Europe
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Problems with the Q_OBJECT-Macro

    Ahhh, Im one step further.
    But now gdb on eclipse stucks with the message:
    Can't find a source file at "widgets/qlineedit.h"
    Locate the file or edit the source lookup path to include its location.
    So where should this source-code installed? I thought I have it all with the qt4-dev-package of debian?

    Thank you

    Sincerely Tok

  7. #7
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Problems with the Q_OBJECT-Macro

    a) did you use #include <QLineEdit>?
    b) Look, if under project->properties->C++ Include paths the right directories are set.

Similar Threads

  1. Problems with Q_OBJECT macro
    By dbrmik in forum Qt Programming
    Replies: 21
    Last Post: 26th February 2009, 15:10
  2. Q_OBJECT macro - what exactly does it do?
    By magland in forum Qt Programming
    Replies: 3
    Last Post: 26th September 2007, 11:30
  3. Q_OBJECT macro issue
    By kandalf in forum Qt Programming
    Replies: 2
    Last Post: 23rd January 2007, 20:28
  4. QT4 Plugins - problems, problems
    By NormanDunbar in forum Qt Programming
    Replies: 6
    Last Post: 9th May 2006, 16:39

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.