Results 1 to 3 of 3

Thread: Pass struct array to function

  1. #1
    Join Date
    Mar 2012
    Posts
    1
    Qt products
    Qt4
    Platforms
    Windows Symbian S60

    Default Pass struct array to function

    How would I go about making this work I seem to have hit a wall. Also I REALLYYYY don't want to use a global struct (tisktisk). Thanks



    void playerslist(int qnum);


    void q1(){} //No content right now but wouldn't matter anyway


    void playerslist(int qnum){

    struct playerbase{}
    playerbase * player=new playerbase [];

    q1(); //What would I do here to pass *player to q1(); ?
    }

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Pass struct array to function

    Do you mean
    Qt Code:
    1. void q1(struct playerbase* pPlayerBase)
    2. {
    3.  
    4. }
    To copy to clipboard, switch view to plain text mode 
    ?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Pass struct array to function

    since op is using new, not free, I will assume this is C++ and not C: There is no need for struct keyword in signature.
    Qt Code:
    1. void func( ClassName* pClassName)
    2. {
    3. }
    4.  
    5. void foo()
    6. {
    7. ClassName* ptr = new ClassName;
    8.  
    9. func(ptr);
    10. }
    To copy to clipboard, switch view to plain text mode 

    Having said that, it is a very rare occurrence that anyone should be using new[] instead of e.g. QList or std::vector/queue.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

Similar Threads

  1. Pass data from QT to javascript function
    By thanhluanbk88 in forum Qt Programming
    Replies: 3
    Last Post: 3rd March 2011, 10:40
  2. Replies: 13
    Last Post: 30th November 2010, 12:47
  3. Call ActiveX function with struct parametr
    By agealex in forum Qt Programming
    Replies: 3
    Last Post: 23rd October 2010, 14:14
  4. Replies: 14
    Last Post: 1st December 2009, 20:45
  5. How to pass a QComboBox to a function?
    By Ricardo_arg in forum General Programming
    Replies: 4
    Last Post: 9th March 2008, 22:16

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.