Results 1 to 8 of 8

Thread: problem with array

  1. #1
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default problem with array

    Hi I need to do this but I haven't problem with array (don't compile):
    Qt Code:
    1. GLfloat position[4];
    2. GLfloat[] getPosition() {return &position[0]; }
    To copy to clipboard, switch view to plain text mode 
    How can I do this? Thanks
    Regards

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: problem with array

    Quote Originally Posted by mickey
    How can I do this? Thanks
    There are two solutions:
    Qt Code:
    1. GLfloat[4] getPosition() {return position; }
    To copy to clipboard, switch view to plain text mode 
    or more efficient and more dangerous:
    Qt Code:
    1. GLfloat * getPosition() {return &position[0]; }
    2. // or
    3. // GLfloat * getPosition() {return position; }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: problem with array

    Sorry, your firset solution (I didn't try the second because I don't need a pointer value) give me this error:
    Qt Code:
    1. C:\Qt\3.2.0Educational\include\qsignalslotimp.h(66): fatal error C1903: unable to recover from previous error(s); stopping compilation
    To copy to clipboard, switch view to plain text mode 
    Regards

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: problem with array

    Quote Originally Posted by mickey
    unable to recover from previous error(s); stopping compilation
    What is the first error?

  5. #5
    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: problem with array

    Quote Originally Posted by mickey
    Sorry, your firset solution (I didn't try the second because I don't need a pointer value)...
    Qt Code:
    1. int arr[4] = {0, 1, 2, 3};
    2. int *arrPtr = arr;
    3. printf("%d\n", arrPtr[2]);
    To copy to clipboard, switch view to plain text mode 
    Guess what it prints...

  6. #6
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: problem with array

    There isn't first error..There are many errors after like those:
    Qt Code:
    1. error C2061: syntax error : identifier 'getPosition'
    2. error C3400: 'string': unexpected token/character encountered in attribute block
    3. error C2334: unexpected token(s) preceding '{'; skipping apparent function body
    To copy to clipboard, switch view to plain text mode 
    Regards

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: problem with array

    Quote Originally Posted by mickey
    There isn't first error..
    That's quite interesting

    You will have to use one of these:
    Qt Code:
    1. GLfloat * getPosition() {return &position[0]; }
    2. // or
    3. GLfloat * getPosition() {return position; }
    To copy to clipboard, switch view to plain text mode 

  8. #8
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: problem with array

    OK. those solution are write. I wondered how I must code the first solution with [].
    Thanks
    Regards

Similar Threads

  1. Weird problem: multithread QT app kills my linux
    By Ishark in forum Qt Programming
    Replies: 2
    Last Post: 8th August 2008, 10:12
  2. Steps in solving a programming problem?
    By triperzonak in forum General Programming
    Replies: 8
    Last Post: 5th August 2008, 09:47
  3. problem with paint and erase in frame
    By M.A.M in forum Qt Programming
    Replies: 9
    Last Post: 4th May 2008, 21:17
  4. Problem in converting QString to QChar array?
    By KaKa in forum Qt Programming
    Replies: 2
    Last Post: 19th March 2007, 01:38
  5. Replies: 16
    Last Post: 7th March 2006, 16:57

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.