Hallo,
ich möchte eine Qmap im qdebug auslesen, hat eine Ahnung wie das geht.
Map: QMap<QString, int> map;
for(int x=0; x<map.end(); x++ )
{
qDebug()<< ????????
}
Danke
Qmap mit qdebug auslesen
-
- Beiträge: 1379
- Registriert: 6. November 2004 12:03
- Kontaktdaten:
Ein Blick in die Doku sagt:
If you want to navigate through all the (key, value) pairs stored in a QMap, you can use an iterator. QMap provides both Java-style iterators (QMapIterator and QMutableMapIterator) and STL-style iterators (QMap::const_iterator and QMap::iterator). Here's how to iterate over a QMap<QString, int> using a Java-style iterator:
QMapIterator<QString, int> i(map);
while (i.hasNext()) {
i.next();
cout << i.key() << ": " << i.value() << endl;
}
Hallo Leute,
ich versuche seit geraumer Zeit Eine QMap in eine Tabelle auszulesen, funktioniert nur leider nicht.
Bitte um Hilfe
//main.cpp
#include <QtGui>
#include "read_1.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Read_1 mainWidget;
mainWidget.setGeometry(50,50,200,500);
mainWidget.show();
return a.exec();
}
//Read_1.cpp
#include <QTableWidgetItem>
#include <QTableWidget>
#include <QMap>
#include <QMapIterator>
#include "read_1.h"
QMap<QString, int> map;
QMapIterator<QString, int> i(map);
static const int NAME_COLUMN = 0;
static const int KEY_COLUMN = 1;
Read_1::Read_1(QWidget *parent, Qt::WFlags flags) : QMainWindow(parent, flags)
{
map.insert("Max Mustermann", 1);
map.insert("Hanne Musterfrau", 2);
map.insert("Hilde Musterkind", 3);
QStringList headerLables;
headerLables << "Name"<< "Key";
tableWidget = new QTableWidget(this);
tableWidget->setRowCount(10);
tableWidget->setColumnCount( headerLables.count() );
tableWidget->setHorizontalHeaderLabels( headerLables );
int a=1;
// Diese Schleife wird ignoriert
while (i.hasNext()) {
i.next();
QTableWidgetItem *keyCell = new QTableWidgetItem( i.key() );
QTableWidgetItem *nameCell = new QTableWidgetItem(i.value() );
tableWidget->setItem(a, 1, nameCell);
tableWidget->setItem(a, 2, keyCell);
a++;
qDebug()<<i.key();
qDebug()<<i.value();
}
setCentralWidget( tableWidget );
}
Read_1::~Read_1(){}
//Read_1.h
#ifndef READ_1_H
#define READ_1_H
#include <QtGui>
class Read_1 : public QMainWindow
{
Q_OBJECT
public:
Read_1(QWidget *parent = 0, Qt::WFlags flags = 0);
QTableWidget *tableWidget;
QTableWidgetItem * item;
~Read_1();
};
#endif // READ_1_H
ich versuche seit geraumer Zeit Eine QMap in eine Tabelle auszulesen, funktioniert nur leider nicht.
Bitte um Hilfe
//main.cpp
#include <QtGui>
#include "read_1.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Read_1 mainWidget;
mainWidget.setGeometry(50,50,200,500);
mainWidget.show();
return a.exec();
}
//Read_1.cpp
#include <QTableWidgetItem>
#include <QTableWidget>
#include <QMap>
#include <QMapIterator>
#include "read_1.h"
QMap<QString, int> map;
QMapIterator<QString, int> i(map);
static const int NAME_COLUMN = 0;
static const int KEY_COLUMN = 1;
Read_1::Read_1(QWidget *parent, Qt::WFlags flags) : QMainWindow(parent, flags)
{
map.insert("Max Mustermann", 1);
map.insert("Hanne Musterfrau", 2);
map.insert("Hilde Musterkind", 3);
QStringList headerLables;
headerLables << "Name"<< "Key";
tableWidget = new QTableWidget(this);
tableWidget->setRowCount(10);
tableWidget->setColumnCount( headerLables.count() );
tableWidget->setHorizontalHeaderLabels( headerLables );
int a=1;
// Diese Schleife wird ignoriert
while (i.hasNext()) {
i.next();
QTableWidgetItem *keyCell = new QTableWidgetItem( i.key() );
QTableWidgetItem *nameCell = new QTableWidgetItem(i.value() );
tableWidget->setItem(a, 1, nameCell);
tableWidget->setItem(a, 2, keyCell);
a++;
qDebug()<<i.key();
qDebug()<<i.value();
}
setCentralWidget( tableWidget );
}
Read_1::~Read_1(){}
//Read_1.h
#ifndef READ_1_H
#define READ_1_H
#include <QtGui>
class Read_1 : public QMainWindow
{
Q_OBJECT
public:
Read_1(QWidget *parent = 0, Qt::WFlags flags = 0);
QTableWidget *tableWidget;
QTableWidgetItem * item;
~Read_1();
};
#endif // READ_1_H