1

This is my first time using QMap and I don't know what I'm doing wrong.

#include <QMap>
QMap<QString, int> name_sec_age;
name_sec_age.insert("willy", 593381460);

my errors are: "unknown type name 'name_sec_age'" and "expected unqualified id"

I'm using Qt Creator 4.0 with Qt 5.6 on a mac. Side note: the run button on Qt Creator isn't available. To run my app I build it and then open the app from its path in finder. rather annoying.

Kuba hasn't forgotten Monica
  • 95,931
  • 16
  • 151
  • 313
Life4ants
  • 683
  • 2
  • 8
  • 24

2 Answers2

1

You can't run code in the wild like that, it needs to be in a function.

#include <QMap>
#include <QString>
#include <QDebug>

int main() {
    QMap<QString, int> name_sec_age;

    name_sec_age.insert("willy", 593381460);
    qDebug() << name_sec_age;
}
coyotte508
  • 9,175
  • 6
  • 44
  • 63
0

Your setup must be messed up somehow. Perhaps you'll have more luck by installing macports and using Qt/Qt Creator from there.

The following compiles just fine for me under Qt 5.5.1:

#include <QMap>

int main() {
   QMap<QString, int> name_sec_age;
   name_sec_age.insert("willy", 593381460);
}
Kuba hasn't forgotten Monica
  • 95,931
  • 16
  • 151
  • 313