PDA

View Full Version : [solved] Passing QVector between forms



KeineAhnung
23rd May 2014, 07:30
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


#ifndef SUPPORT_H
#define SUPPORT_H

#include <QDateTime>

namespace support {

int w20();
int w6();

}
#endif // SUPPORT_H

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!

Lesiok
23rd May 2014, 08:10
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.

KeineAhnung
23rd May 2014, 09:20
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.

Lesiok
23rd May 2014, 09:34
OK, remember that Qt is nothing like an ordinary C++ library.

KeineAhnung
23rd May 2014, 09:50
I got it to work by created a new file called global:


#ifndef GLOBAL_H
#define GLOBAL_H

#include "card.h"

extern QVector<Card> cards;
extern int cardIndex;

#endif // GLOBAL_H

and the .cpp


#include "global.h"

// Global Variables
int cardIndex = 0;
QVector<Card> cards;


Why do I have to declare the QVector again in the cpp file?