Results 1 to 16 of 16

Thread: Working with QObject

  1. #1
    Join Date
    Oct 2008
    Posts
    306
    Thanks
    6
    Thanked 9 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Working with QObject

    How do I work with QObject? I want a main Object as parent to several others that have several information in them. Ex:

    Qt Code:
    1. QObject-mainParent{
    2. QObject-child{
    3. info1{};
    4. info2{};
    5. }
    6. QObject-child{
    7. info1{};
    8. info2{};
    9. }
    10. QObject-child{
    11. info1{};
    12. info2{};
    13. }
    14. QObject-child{
    15. info1{};
    16. info2{};
    17. }
    18. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by wysota; 15th June 2009 at 21:09. Reason: missing [code] tags

  2. #2
    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: Working with QObject

    What exactly is the problem? What did you already try?
    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.


  3. #3
    Join Date
    Oct 2008
    Posts
    306
    Thanks
    6
    Thanked 9 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Working with QObject

    I guess I just need to know how to to that in a for() loop. And what exactly is QObject, is it a general-purpose object for OOP? Does addChild() create a new object and can I acess it and change-add its value? Can I give the child a name that can be acessed anywhere? Not much of a problem, just searching for guidance.
    I actually want to make several boxes across the screen and give each one several values, such as heigth, width, name, image and be able to receive events from them, ex: click , doubleclick , hover, etc.

  4. #4
    Join Date
    Dec 2006
    Posts
    426
    Thanks
    8
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Working with QObject

    Quote Originally Posted by been_1990 View Post
    I guess I just need to know how to to that in a for() loop. And what exactly is QObject, is it a general-purpose object for OOP? Does addChild() create a new object and can I acess it and change-add its value? Can I give the child a name that can be acessed anywhere? Not much of a problem, just searching for guidance.
    I actually want to make several boxes across the screen and give each one several values, such as heigth, width, name, image and be able to receive events from them, ex: click , doubleclick , hover, etc.
    Your questions beat our guru

  5. #5
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Working with QObject

    I actually want to make several boxes across the screen and give each one several values, such as heigth, width, name, image and be able to receive events from them, ex: click , doubleclick , hover, etc.
    May be you can go for Graphics View framework ? your boxes will be graphics items..

    or you can have several QWidgets on the screen, so u can get all hover, click etc events..
    hope i understood ur prob right

  6. #6
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Working with QObject

    Quote Originally Posted by been_1990 View Post
    I guess I just need to know how to to that in a for() loop. And what exactly is QObject, is it a general-purpose object for OOP? Does addChild() create a new object and can I acess it and change-add its value? Can I give the child a name that can be acessed anywhere? Not much of a problem, just searching for guidance.
    I actually want to make several boxes across the screen and give each one several values, such as heigth, width, name, image and be able to receive events from them, ex: click , doubleclick , hover, etc.
    you seem to be reading an overdose of OOP concepts in theory. Assuming you know inheritance and pointers... start reading the "GUI programming with Qt4" book. At least start to take a look at the tutorials that are presented in QtAssistant. But for that u need to download the Qt. But first u need to figure out your OS. Depending upon the OS u need to select the correct qt sdk. and finally post your next query in NEWBIE forum.

  7. The following user says thank you to nish for this useful post:

    ramsarvan (16th June 2009)

  8. #7
    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.

  9. #8
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Working with QObject

    this guy... "ramsarvan", sits next to me, he thinks my post is BS.

  10. #9
    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: Working with QObject

    Quote Originally Posted by been_1990 View Post
    I guess I just need to know how to to that in a for() loop.
    Eem... what is the problem? You know how to use loops, right?

    And what exactly is QObject, is it a general-purpose object for OOP?
    No, there is no such thing in C++. QObject is a very specific class.

    Does addChild() create a new object and can I acess it and change-add its value?
    I don't see any "addChild()" method in QObject. But even if it was there, it would only establish a parent-child relationship between existing objects.

    Can I give the child a name that can be acessed anywhere?
    QObject::objectName()
    I actually want to make several boxes across the screen and give each one several values, such as heigth, width, name, image and be able to receive events from them, ex: click , doubleclick , hover, etc.
    You mean widgets? Then you need to read about layouts (QLayout and family) as well.
    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.


  11. #10
    Join Date
    Oct 2008
    Posts
    306
    Thanks
    6
    Thanked 9 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Working with QObject

    Quote Originally Posted by aamer4yu View Post
    May be you can go for Graphics View framework ? your boxes will be graphics items..

    or you can have several QWidgets on the screen, so u can get all hover, click etc events..
    hope i understood ur prob right
    But thats exactly what I'll do. I'll read the number of .xml files in a directory. Then for each .xml file I'll load a QIcon data saved in a node, read other info from other nodes. Then put the QIcon pixmap in a QGraphicsView thats already set up. I need to somehow tie all the .xml nodes together so when I click on, let's say, QGraphicsView.firstChild() I can acess the other info that would be loaded into the same object as the graphic I just clicked. I hope I explained myself clearly. I've already done this using Actionscript 3.0 in Flash, but using QT beats me.
    Last edited by been_1990; 16th June 2009 at 18:16.

  12. #11
    Join Date
    Oct 2008
    Posts
    306
    Thanks
    6
    Thanked 9 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Talking Re: Working with QObject

    I guess I started with my left foot in this thread... I started asking something that wont take me to where I want to go. This is what I want to know:

    Whats the best way to load a pixmap from a data file? Using QGraphicsView? Or making a new widget for each pixmap? I want to be able to grab events that happen to the object holding the pixmap.

    I'm really sorry for the wrong explanation of what I needed, one day I'll get it rigth from the beggining...

  13. #12
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Working with QObject

    Whats the best way to load a pixmap from a data file?
    QPixmap::load or QPixmap::loadFromData
    Or making a new widget for each pixmap? I want to be able to grab events that happen to the object holding the pixmap.
    That depends on what kind of events you want to capture..and what you want to do on those events.
    For basic mouse clicks and double clicks, use QLabel will be good enough. You can you QLabel in grid layout and show multiple pics..
    If you want some anitmation, go for graphics view. You can refer Embedded dialog demo in Qt Demo (since 4.5) . Instead of dialog, you can have your widget or graphics item.

    Can refer more if you tell what actions you want to perform on events on the pixmap.

  14. #13
    Join Date
    Oct 2008
    Posts
    306
    Thanks
    6
    Thanked 9 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Post Re: Working with QObject

    Qt Code:
    1. Functionality needed:
    2.  
    3. Click/Double-Click ;
    4. Click&Drag;
    5. On Hover animation;
    6. Speed;
    7. Left-Click menu;
    To copy to clipboard, switch view to plain text mode 

  15. #14
    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: Working with QObject

    Go for QGraphicsView and friends.
    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.


  16. #15
    Join Date
    Oct 2008
    Posts
    306
    Thanks
    6
    Thanked 9 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Working with QObject

    Ok, I'll use QGraphicsView. Now back to my first question, how can I group some data? In a array? Or is there something more "QT"? Ex:

    Qt Code:
    1. arrayMain{
    2. obj1{"myname", 01001010-myData, myPlaceInTheWorld};
    3. obj2{"myname", 01401010-myData, myPlaceInTheWorld};
    4. obj3{"myname", 01021010-myData, myPlaceInTheWorld};
    5. obj4{"myname", 01042210-myData, myPlaceInTheWorld};
    6. }
    To copy to clipboard, switch view to plain text mode 

  17. #16
    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: Working with QObject

    Group it the way you want... I don't really understand the problem. Your data has some structure, so represent that structure using classes and instances of them.
    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. 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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.