Hoffe Ihr könnt mir nochmals weiterhelfen.
Ich habe eine Klasse MainWindow und öffne einen QDialog mit 2 Comboboxen.
Dabei möchte ich einen QString übergeben, leider kommt dieser immer leer an.
Wenn ich debugge und auf die Variable rs232config zeige, steht "not in scope".
Irgend etwas habe ich da wohl falsch verstanden.
Danke für Eure Mühe
Aufruf von QDialog:
Code: Alles auswählen
void MainWindow::on_pushButton_2_clicked()
{
tmp_RS232Config = data_rs232config;
RS232Configfrm * f1;
QString a;
a="test";
f1 = new RS232Configfrm(a,this); [b]//Aufruf mit a="test" [/b]
connect(f1, SIGNAL(s_tmp_rs232config_port(QString)),this, SLOT(tmp_rs232config_port(QString)));
connect(f1, SIGNAL(s_tmp_rs232config_baudrate(QString)),this, SLOT(tmp_rs232config_baudrate(QString)));
int x
x=f1->exec();
if (x==1)
{
data_rs232config = tmp_RS232Config;
}
else
{
tmp_RS232Config = data_rs232config;
}
}Code: Alles auswählen
#ifndef RS232CONFIGFRM_H
#define RS232CONFIGFRM_H
#include <QDialog>
#include "globalstructs.h"
namespace Ui {
class RS232Configfrm;
}
class RS232Configfrm : public QDialog {
Q_OBJECT
public:
RS232Configfrm(QString rs232config, QWidget *parent = 0);[b] // a="text" sollte hier in QString rs232config kopiert werden[/b]
~RS232Configfrm();
protected:
void changeEvent(QEvent *e);
private:
Ui::RS232Configfrm *ui;
signals:
void s_tmp_rs232config_port(QString);
void s_tmp_rs232config_baudrate(QString);
private slots:
void on_comboBox_2_activated(QString );
void on_comboBox_activated(QString );
};
Code: Alles auswählen
#endif // RS232CONFIGFRM_H
#include "rs232configfrm.h"
#include "ui_rs232configfrm.h"
RS232Configfrm::RS232Configfrm(QString rs232config, QWidget // a="text" sollte hier in QString rs232config kopiert werden[/b]*parent) :
QDialog(parent),
ui(new Ui::RS232Configfrm)
{
ui->setupUi(this);
ui->comboBox->addItem("COM0", QVariant::fromValue(QString("COM0")));
ui->comboBox->addItem("COM1", QVariant::fromValue(QString("COM1")));
//ui->comboBox->setCurrentIndex(4);
ui->comboBox->addItem(rs232config,rs232config); [b]//rs232config= leer / "not in scope"[/b]
ui->comboBox_2->addItem("115200", QVariant::fromValue(QString("BAUD115200")));
ui->comboBox_2->addItem("128000", QVariant::fromValue(QString("BAUD128000")));
//ui->comboBox_2->setCurrentIndex(11);
ui->comboBox_2->addItem(rs232config,rs232config);
}
RS232Configfrm::~RS232Configfrm()
{
delete ui;
}
void RS232Configfrm::changeEvent(QEvent *e)
{
QDialog::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}
void RS232Configfrm::on_comboBox_activated(QString text)
{
emit s_tmp_rs232config_port(text);
}
void RS232Configfrm::on_comboBox_2_activated(QString text)
{
emit s_tmp_rs232config_baudrate(text);
}Großes Dankeschön für alle Tipps und Ratschläge
Bin auch gerne für andere Verbesserungsvorschläge zu haben
Danke, schöne Abend
lg Lukas