Results 1 to 7 of 7

Thread: QWidget - Q_OBJECT makes the widget disappear

  1. #1
    Join Date
    Jul 2009
    Posts
    9
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QWidget - Q_OBJECT makes the widget disappear

    Ok hey guys, I have a very very weird bug. If I add the Q_OBJECT line to the class it makes it disappear. I have kept the class very small to show the bug. The class works like a charm when Q_OBJECT isn't present, but I need it to emit signals.
    By disappear I mean that it doesn't show the class at all anymore on the UI, on the widget. It still somewhat works, because it creates a new window if I set the parent to NULL, indicating that the class is still somewhat operational.

    rgcbutton.h
    Qt Code:
    1. #ifndef RGCBUTTON_H
    2. #define RGCBUTTON_H
    3.  
    4. #include <QWidget>
    5.  
    6. class rgcbutton : public QWidget
    7. {
    8. //Q_OBJECT
    9.  
    10. public:
    11. rgcbutton(QWidget *parent);
    12. ~rgcbutton();
    13.  
    14. };
    15.  
    16. #endif // RGCBUTTON_H
    To copy to clipboard, switch view to plain text mode 


    rgcbutton.cpp
    Qt Code:
    1. #include "rgcbutton.h"
    2. #include <QMouseEvent>
    3.  
    4. rgcbutton::rgcbutton(QWidget *parent) : QWidget(parent)
    5. {
    6. QImage ximg; ximg.load("skins/default/images/exit_inactive.png");
    7. setStyleSheet("background-image: url(skins/default/images/exit_inactive.png);");
    8. setFixedSize(ximg.size());
    9. }
    10. rgcbutton::~rgcbutton() { }
    To copy to clipboard, switch view to plain text mode 



    Implementation (Some random QWidget
    Qt Code:
    1. login::login(QWidget *parent) : QWidget(parent, Qt::FramelessWindowHint), ui(new Ui::login)
    2. {
    3. ui->setupUi(this); move(QApplication::desktop()->geometry().center() - rect().center());
    4.  
    5. rgcbutton *TT = new rgcbutton(this);
    6. TT->move(20, 20);
    7. }
    To copy to clipboard, switch view to plain text mode 



    I'm stuck on this and I don't know what's happening. Your help is very much appreciated. This is the warning I get when I compile without Q_OBJECT. Maybe it helps: rgcbutton.h:0: Warning: No relevant classes found. No output generated.


    Regards,
    Sir Rogers
    Last edited by wysota; 25th January 2010 at 09:35. Reason: Missing [code] tags

  2. #2
    Join Date
    Jul 2009
    Posts
    9
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QWidget - Q_OBJECT makes the widget disappear

    I have no idea why, but adding another widget into the rgcbutton class solves the problem:

    QWidget *randomWidget;
    randomWidget = new QWidget(this);

    This really doesn't make sense.

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QWidget - Q_OBJECT makes the widget disappear

    Your code doesn't make much sense either Use QLabel with QPixmap instead of your class.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. #4
    Join Date
    Jul 2009
    Posts
    9
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QWidget - Q_OBJECT makes the widget disappear

    I narrowed it down to a basic level so it was easier to read. I'm using it to create a button with images. I need the mouseMoveEvent for that.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QWidget - Q_OBJECT makes the widget disappear

    But you don't need the stylesheet part. Having a paint event instead is better. So is defining sizeHint().
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #6
    Join Date
    Jul 2009
    Posts
    9
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QWidget - Q_OBJECT makes the widget disappear

    Could you please explain in code what you mean? I'm not following.

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QWidget - Q_OBJECT makes the widget disappear

    Open up Qt Assistant and type in "paintEvent", then read the page about QWidget that pops up.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 1
    Last Post: 30th March 2009, 14:28
  2. Dynamic widget not displayed upon Qwidget
    By ashukla in forum Qt Programming
    Replies: 5
    Last Post: 17th December 2007, 11:11
  3. get custom widget to inherit qwidget
    By CopyrightPhilly in forum Qt Tools
    Replies: 3
    Last Post: 4th October 2007, 08:58
  4. QLabel::setText causes part of widget to disappear
    By Pieter from Belgium in forum Qt Programming
    Replies: 4
    Last Post: 6th July 2007, 09:22
  5. Replies: 9
    Last Post: 8th May 2006, 14:21

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.