Results 1 to 5 of 5

Thread: [solved] Passing QVector between forms

  1. #1
    Join Date
    Apr 2014
    Posts
    116
    Thanks
    8
    Qt products
    Qt5
    Platforms
    MacOS X

    Default [solved] Passing QVector between forms

    Hi there,

    my program is slowly growing and I start getting into problems manage the user input. To structure the program I started to create new windows for special task. So far I managed to communicate between the windows using signals and slots but now I am looking for a method to have a QVector available in several windows.
    I already created a support file with functions I need in several forms:
    support.h
    Qt Code:
    1. #ifndef SUPPORT_H
    2. #define SUPPORT_H
    3.  
    4. #include <QDateTime>
    5.  
    6. namespace support {
    7.  
    8. int w20();
    9. int w6();
    10.  
    11. }
    12. #endif // SUPPORT_H
    To copy to clipboard, switch view to plain text mode 
    If I declare the QVector, from a custom class, here, would it be available in all forms that include the support file?

    Thanks for looking into this!
    Last edited by KeineAhnung; 23rd May 2014 at 10:24.

  2. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,540
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Passing QVector between forms

    But what is your problem ? So really asking the question: how to pass a value between two objects or how to make variable global. These are the basics of C++ and have nothing to do with Qt.

  3. #3
    Join Date
    Apr 2014
    Posts
    116
    Thanks
    8
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: Passing QVector between forms

    Hi Lesiok,

    currently I do not have a problem. I wanted to ask first before I make major changes to my code. I think I want to declare a global variable. Thanks for the hint in the right direction.

  4. #4
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,540
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Passing QVector between forms

    OK, remember that Qt is nothing like an ordinary C++ library.

  5. #5
    Join Date
    Apr 2014
    Posts
    116
    Thanks
    8
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: Passing QVector between forms

    I got it to work by created a new file called global:
    Qt Code:
    1. #ifndef GLOBAL_H
    2. #define GLOBAL_H
    3.  
    4. #include "card.h"
    5.  
    6. extern QVector<Card> cards;
    7. extern int cardIndex;
    8.  
    9. #endif // GLOBAL_H
    To copy to clipboard, switch view to plain text mode 
    and the .cpp
    Qt Code:
    1. #include "global.h"
    2.  
    3. // Global Variables
    4. int cardIndex = 0;
    5. QVector<Card> cards;
    To copy to clipboard, switch view to plain text mode 

    Why do I have to declare the QVector again in the cpp file?
    Last edited by KeineAhnung; 23rd May 2014 at 10:24.

Similar Threads

  1. Replies: 9
    Last Post: 27th March 2014, 09:45
  2. Replies: 3
    Last Post: 6th May 2013, 07:35
  3. Passing variables between forms.
    By Splatify in forum Newbie
    Replies: 9
    Last Post: 21st February 2011, 11:12
  4. Multiple Forms and vertical layout in forms
    By eva2002 in forum Qt Programming
    Replies: 0
    Last Post: 13th January 2010, 05:05
  5. Replies: 2
    Last Post: 1st May 2009, 07:35

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
  •  
Qt is a trademark of The Qt Company.