ich bin absoluter Qt Anfänger und stehe gleich bei einem vmtl. eher einfachen Problem auf dem Schlauch:
Ich möchte bei Änderung des Index einer ComboBox im GUI ein Label ändern:
die Header Datei sieht wie folgt aus:
Code: Alles auswählen
#ifndef UI_TESTDIALOG_H
#define UI_TESTDIALOG_H
#include <QVariant>
#include <QAction>
#include <QApplication>
#include <QButtonGroup>
#include <QComboBox>
#include <QDialog>
#include <QDialogButtonBox>
#include <QGraphicsView>
#include <QLabel>
#include <QSpinBox>
#include <QObject>
class Ui_testdialog: public QObject
{
Q_OBJECT
public:
...
QComboBox *comboBox;
QLabel *label;
void setupUi(QDialog *);
public slots:
void setzValue(QString);
signals:
void writeValue(QString);
};
namespace Ui {
class testdialog: public Ui_testdialog {};
} // namespace UiCode: Alles auswählen
#include "ui_testdialog.h"
void Ui_testdialog::setupUi(QDialog *testdialog)
{
...
comboBox = new QComboBox(testdialog);
...
label = new QLabel(testdialog);
...
QObject::connect(comboBox, SIGNAL(currentIndexChanged(QString)), testdialog, SLOT(setzValue(QString)));
QObject::connect(testdialog, SIGNAL(writeValue(QString)), label, SLOT(setText(QString)));
QMetaObject::connectSlotsByName(testdialog);
} // setupUi
void Ui_testdialog::setzValue(QString str)
{
// ... hier soll mit dem String noch was passieren, aber das ist vorerst irrelevant
emit writeValue(str);
}
Konnektiere ich direkt, dann funktioniert es hingegen, folgendes funktioniert also:
Code: Alles auswählen
QObject::connect(comboBox, SIGNAL(currentIndexChanged(QString)), label, SLOT(setText(QString)));
Danke
Markus