Sunday, July 20th 2008, 2:31am UTC+1

You are not logged in.

  • Login
  • Register

1

Thursday, April 10th 2008, 7:11pm

QValueVector class details

hey,

Imusing a qvaluevector V to hold a set of classes of another type. Could anyone tell me as to hw i can access the individual members of the classes from the vector V? if i use v->getpoly() or some similar function, i am getting an error.
Ppl kingly help out as this is very important that i get this working.

A
  • Go to the top of the page

Messenger

Intermediate

Posts: 329

Location: Lt

2

Friday, April 11th 2008, 6:27am

RE: QValueVector class details

Depends on what you store.

Source code

1
2
3
4
5
6
7
8
QValueVector<A> vvA;
QValueVector<A*> vvPointerA;

vvA.push_back(A(...));
vvA[0].someFunction();

vvPointerA.push_back(new A(...));
vvPointerA[0]->someFunction();
Fighting fire with fire.
  • Go to the top of the page

3

Tuesday, April 15th 2008, 8:28pm

did as you said. I am getting an error saying "left of '.getVehicleClasses' must have class/struct/union type". getVehicleClasses() is the function i need to call.
Any other suggestions?
  • Go to the top of the page

Messenger

Intermediate

Posts: 329

Location: Lt

4

Wednesday, April 16th 2008, 3:03pm

Example which compiles

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <qapplication.h>
#include <qvaluevector.h>

class Test
{
public:
    void test()
    {
        qDebug("Test test()");
    }
    void test2()
    {
        qDebug("Test test2()");
    }
};

int main ( int argc, char *argv[] )
{
    QValueVector<Test> vv;
    QValueVector<Test*> pp;
    vv.push_back(Test());
    vv.push_back(Test());
    pp.push_back(new Test());
    pp.push_back(new Test());
    vv[0].test();
    vv[1].test2();
    pp[0]->test();
    pp[1]->test2();
    int i;
    for (i = 0; i < pp.count(); ++i)
        delete pp[i];
    return 0;
}

Make example project which shows the problem.
Fighting fire with fire.
  • Go to the top of the page

5

Wednesday, April 16th 2008, 5:51pm

Thanks so much for the post messenger. This code works just fine. But i do not know what to do when the function i call returns another object. I am pasting my code snippet below

<CODE>
typedef QValueVector<const GKVehicle*> Vehicle;
Vehicle veh;
Vehicle pubveh; // Containers for normal and public transport vehicles
const GKTrafficDemand *gtd;
const GKPublicLinePlan *gplp;


gtd=gsid.getDemand(); // Acquiring the demand from the particular scenario for non-public vehicles
gplp= gsid.getPublicLinePlan(); // Public transport being considered here
veh = gtd->getUsedVehicles(); // Extracting the vehicles used in the particular scenario
pubveh = gplp->getUsedVehicles(); // Same thing for public vehicles

Vehicle_modalities_names = new CString[ Number_of_vehicle_modalities ] ;
for(int i=0;i<pubveh.size();i++)
{
veh.append(pubveh); // creating a single vector of all vehicles used in this scenario. Makes it easier to analyze
}
Number_of_vehicle_modalities = veh.size(); // Total number of vehicles

for ( i=0;i<Number_of_vehicle_modalities;i++)
{
Vehicle_modalities_names[i] = ((veh[i]->getVehicleClasses()).getType())->getName().ascii();
}
</CODE>

The problem im facing is, veh[i]->getVehicleClasses() returns another object, whose function i have to call, which returns another object which is what i need. I am not able to handle this multiple object heirarchy. It will be very helpful if you guys can guide me with this.
  • Go to the top of the page

Messenger

Intermediate

Posts: 329

Location: Lt

6

Wednesday, April 16th 2008, 6:12pm

What is exactly error?
Yet another example

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <qapplication.h>
#include <qvaluevector.h>

class Test
{
public:
    void test()
    {
        qDebug("Test test()");
    }
    void test2()
    {
        qDebug("Test test2()");
    }
    void test3() const
    {
        qDebug("Test test3()");
    }
private:
    int m_obj;
};

int main ( int argc, char *argv[] )
{
    QValueVector<Test> vv;
    QValueVector<Test*> pp;
    
    vv.push_back(Test());
    vv.push_back(Test());
    pp.push_back(new Test());
    pp.push_back(new Test());
    vv[0].test();
    vv[1].test2();
    pp[0]->test();
    pp[1]->test2();
    
    QValueVector<const Test*> ppconst; 
    ppconst.push_back(new Test());
    ppconst.push_back(new Test());
    
    // ppconst[0]->test(); // will not compile
    ppconst[1]->test3();
    
    int i;
    for (i = 0; i < pp.count(); ++i)
        delete pp[i];
    for (i = 0; i < ppconst.count(); ++i)
        delete ppconst[i];
    return 0;
}

imho use
typedef QValueVector<GKVehicle*> Vehicle;

And make full compilable example which shows the issue.
Fighting fire with fire.

This post has been edited 1 times, last edit by "Messenger" (Apr 16th 2008, 6:22pm)

  • Go to the top of the page

7

Wednesday, April 16th 2008, 6:27pm

hey
messenger,

this is the error message i get when i build the code

TDadditional.cpp
c:\avani's work\workspace_ver5\source\tdadditional.cpp(367) : error C2039: 'getType' : is not a member of 'QValueVector<class GKVehicleClass *>'
c:\avani's work\workspace_ver5\source\tdadditional.cpp(367) : error C2227: left of '->getName' must point to class/struct/union
c:\avani's work\workspace_ver5\source\tdadditional.cpp(367) : error C2228: left of '.ascii' must have class/struct/union type
UserFile.cpp
Error executing cl.exe.
  • Go to the top of the page

Messenger

Intermediate

Posts: 329

Location: Lt

8

Wednesday, April 16th 2008, 6:34pm

What return
veh->getVehicleClasses() (the GKVehicle::getVehicleClasses function)
?
from name (and error) I suppose it returns some kind of container of class instances not a class instance.
Fighting fire with fire.
  • Go to the top of the page

9

Wednesday, April 16th 2008, 6:49pm

Thanks messenger. I will try to modify the code to accomodate any container objects that maybe produced. Thanks again. Will get back once i have done that
  • Go to the top of the page

Rate this thread