Results 1 to 16 of 16

Thread: Working with QObject

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #12
    Join Date
    Jan 2008
    Posts
    6
    Thanks
    1
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Working with QObject

    All Qt Widgets are derived from QObject.

    Yes you can use QObject, if you just want a pure C++ object
    (ie, if you dont need SIGNAL, SLOTS & PROPERTIES)
    Also, the Q_OBJECT macro is mandatory for any object (including QObject)
    that implements signals, slots or properties.

    You can set a object name to your object as follows:
    setObjectName("xxxx");

    Qt Code:
    1. class MainWidget : public QWidget
    2. {
    3. Q_OBJECT
    4. // follow Qt standards.
    5. constructor
    6. {
    7. QStringList items, objects;
    8. items<<"label1"<<"label2"<<label3";
    9. objects<<"objl1"<<objl2"<<objl3";
    10.  
    11. QVBoxLayout* layout = new QVBoxLayout();
    12. for (int i = 0; items.count(); i++)
    13. {
    14. QLabel* wid = new QLabel (items.at(i), this);
    15. // Other way:
    16. // QLabel* wid = new QLabel (items.at(i));
    17. // wid.setParent (this);
    18. setObjectName (objects.at(i)); /* Set the object name */
    19. wid->setFixedSize(20, 20); /* Height, Width */
    20. }
    21.  
    22. QList<QWidget *> widgets = this->findChildren<QWidget *>("objl1");
    23. // returns you the list of widgets with the name "objl1"
    24. if(widgets.count() > 0)
    25. widgets[0]->setFixedSize(40,40); //changing the size
    26.  
    27. }
    28. }
    To copy to clipboard, switch view to plain text mode 
    Now all label boxes you have created becomes children of your main
    widget. And you can use findChildren and modify their properties.
    Please modify the code with fixing syntax issues and Qt standards,
    it should work fine.

    Thanks,
    Ram
    Last edited by ramsarvan; 16th June 2009 at 08:19.

Similar Threads

  1. QObject signal/slot not working
    By Msnforum in forum Qt Programming
    Replies: 4
    Last Post: 24th January 2009, 22:50
  2. py2app-deployed PyQt app -- throws QObject threading error
    By tory108 in forum Installation and Deployment
    Replies: 4
    Last Post: 20th January 2009, 20:16
  3. QResource Stopped Working
    By JPNaude in forum Qt Programming
    Replies: 0
    Last Post: 22nd October 2008, 12:26
  4. QObject and copy Constructors
    By December in forum Qt Programming
    Replies: 5
    Last Post: 17th July 2008, 16:14
  5. GUI thread and Working thread comunication
    By FasTTo in forum Qt Programming
    Replies: 2
    Last Post: 13th September 2007, 15:31

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
  •  
Qt is a trademark of The Qt Company.