Results 1 to 9 of 9

Thread: structures in QT

  1. #1
    Join Date
    Jan 2010
    Posts
    28
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default structures in QT

    How to use structures in QT?

  2. #2
    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: structures in QT

    Are you familiar with C++ ??
    Its the same way in Qt.

  3. #3
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: structures in QT

    It's Qt, not QT, and it's a framework, not a language, so you use them in the same way as when not using Qt.

  4. #4
    Join Date
    Nov 2010
    Posts
    48
    Thanks
    5
    Thanked 4 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: structures in QT

    even I tried to use Struct but its not working
    here is the code
    Qt Code:
    1. struct mystruct
    2. {
    3. QString title;
    4. QString link;
    5. }*p;
    6.  
    7.  
    8.  
    9. in cpp file
    10. p->title = "hello";
    11. p->link ="http://...";
    To copy to clipboard, switch view to plain text mode 
    But its not working.
    Could you please help me to get a sample code to store and retrieve data from struct?

  5. #5
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: structures in QT

    Say exactly how it's not working, it gives errors at compile time, it give errors at run-time, what are the errors, describe the problem you have.

    //just my guess... does p get initialized? before you access it's members?

  6. #6
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: structures in QT

    @Zlatomir: I can bet it's not
    @somnathbanik: Read this : link, at least the beginning (ch. 6.2).

  7. #7
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: structures in QT

    structs are a C'ism. Since you need to be using C++ to use Qt you should be using classes. Structs just resolve to a class with public access by default, which is bad (no encapsulation of data).

  8. #8
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: structures in QT

    Quote Originally Posted by squidge View Post
    structs are a C'ism. Since you need to be using C++ to use Qt you should be using classes. Structs just resolve to a class with public access by default, which is bad (no encapsulation of data).
    Stroustrup makes extensive use of structs throughout "The C++ Programming Language". Sometimes, data is just data and doesn't need to be abstracted away.

    Stroustrup on structs vs. classes.

  9. #9
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: structures in QT

    I agree, if your just reading directly from files (carefully) into structures then you don't need classes. You can always add methods to structs/classes for convenience. Adding methods to structures does seem strange, but works just the same.

    However, if I'm designing data structures for an application, I will rarely, if ever, use a struct. I like to control access to my class members, knowing that there is only one possible place in the application that can modify key variables.

Similar Threads

  1. How to properly delete structures?
    By aarelovich in forum General Programming
    Replies: 5
    Last Post: 24th February 2009, 00:39
  2. APIs and Data structures
    By crazymoonboy in forum Qt Programming
    Replies: 0
    Last Post: 30th September 2008, 07:56
  3. structures to a file (read and write)
    By baray98 in forum Qt Programming
    Replies: 5
    Last Post: 10th February 2008, 20:12
  4. Replies: 1
    Last Post: 13th September 2006, 12:14
  5. Replies: 2
    Last Post: 17th April 2006, 21:30

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.