How to use structures in QT?
How to use structures in QT?
Are you familiar with C++ ??
Its the same way 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.
even I tried to use Struct but its not working
here is the code
But its not working.Qt Code:To copy to clipboard, switch view to plain text mode
Could you please help me to get a sample code to store and retrieve data from struct?
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?
@Zlatomir: I can bet it's not
@somnathbanik: Read this : link, at least the beginning (ch. 6.2).
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.
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.
Bookmarks