PDA

View Full Version : problem with namespaces



steve918
17th September 2006, 16:36
It's been many years since I've written anything in c++ so bear with me. I'm trying to create a namespace for my project that will house all of the global objects and things for the project.

I have the folling name space set up.

myapp.h
-----


#include <QtGui>

namespace myapp {
QList<QPixmap> statusIcons;
statusIcons.insert(0,QPixmap(QString(":/icons/22/images/nuvola/22x22/ledgreen.png")));
statusIcons.insert(0,QPixmap(QString(":/icons/22/images/nuvola/22x22/ledyellow.png")));
statusIcons.insert(0,QPixmap(QString(":/icons/22/images/nuvola/22x22/ledorange.png")));
statusIcons.insert(0,QPixmap(QString(":/icons/22/images/nuvola/22x22/ledred.png")));
}

I'm accessing it like this:

frmMain.cpp
-----


void frmMain::setStatus(int status) {
if(status<myapp::statusIcons.count())
statusLight->setPixmap(myapp::statusIcons[status]);
}

which gives me the following errors:

../include/myapp.h:28: error: expected constructor, destructor, or type conversion before ‘.’ token
../include/myapp.h:29: error: expected constructor, destructor, or type conversion before ‘.’ token
../include/myapp.h:30: error: expected constructor, destructor, or type conversion before ‘.’ token
../include/myapp.h:31: error: expected constructor, destructor, or type conversion before ‘.’ token

I'm guessing that the Qt datatypes aren't available or something inside my namespace, but I'm not really sure how to fix it.

thanks in advance.
--Steven

jacek
17th September 2006, 17:55
statusIcons.insert(0,QPixmap(QString(":/icons/22/images/nuvola/22x22/ledgreen.png")));
statusIcons.insert(0,QPixmap(QString(":/icons/22/images/nuvola/22x22/ledyellow.png")));
statusIcons.insert(0,QPixmap(QString(":/icons/22/images/nuvola/22x22/ledorange.png")));
statusIcons.insert(0,QPixmap(QString(":/icons/22/images/nuvola/22x22/ledred.png")));

You can't put bare code inside namespace, only declarations.