just wondering if there is a set way of doing structs in qt. i have made structs before in the past using C, but im not too sure about using C++ to do it and to make it work with the Qt stuff. any idea's???
just wondering if there is a set way of doing structs in qt. i have made structs before in the past using C, but im not too sure about using C++ to do it and to make it work with the Qt stuff. any idea's???
Try the same way as in C
Qt Code:
struct Point { int x; int y; };To copy to clipboard, switch view to plain text mode
BTW. Structs are treated by C++ as public classes, so you can add methods to them.
ah ok thankyou...whilst im on the subject of storage, would it be easier to have a 2-d array of booleans or an array of linked lists??how would i create a 2-d array of booleans anyway because ive never tried it before - even with C??
It depends. In general there are no such things as 2D arrays. How many bools do you need in each "row"? Maybe you could use bit fields?Originally Posted by therealjag
well i'd probably need around 30 maximum but around 10 would do for now....what are bit fields though i have never used them before?It depends. In general there are no such things as 2D arrays. How many bools do you need in each "row"? Maybe you could use bit fields?
Then bitfields will do fine.
Qt Code:
struct bfentry{ unsigned int one:1, two:1, three:1, four:1, //... thirtytwo:1; }To copy to clipboard, switch view to plain text mode
The above structure occupies.... 4 bytes Making it an array is easy now;
Of course you can also use: std::vector< std::vector< bool > >
Dear All,
I've a similar problem, i need a global struct such as:
I've put the previous code in a .h file and the follow:Qt Code:
struct _Stxy1000{ double dY[1000]; double dX[1000]; }To copy to clipboard, switch view to plain text mode
in a .cpp file which include the .h as definition.Qt Code:
struct _Stxy1000 _stxy1000;To copy to clipboard, switch view to plain text mode
When i use the struct field members in a .cpp, the compiler rise up some problems, such as "multiple definition" of the _stxy1000 variable.
Do you think i should use extern in the declaration?
Could you please post a c-like code??
Thanks in advance.
Andrea
Last edited by wysota; 6th June 2011 at 11:55. Reason: changed [qtclass] to [code]
Ah... so that explains why Fullmetalcoder can, in the "devqthighlighter.h" header of his "DevQt" project, useOriginally Posted by wysota
It compiles with a ton of warnings, an executable, but no errors. If I change the declaration to "struct CodeBlock;" and compile then I get a ton of errors and no executable.Qt Code:
class CodeBlock; .... .... struct CodeBlock{ ... }To copy to clipboard, switch view to plain text mode
Bookmarks