QLineEdit im Hauptfenster nach Dialog nicht beschreibbar

Alles rund um die Programmierung mit Qt
Antworten
Marcus Breuer
Beiträge: 113
Registriert: 31. März 2011 17:19
Wohnort: Aachen
Kontaktdaten:

QLineEdit im Hauptfenster nach Dialog nicht beschreibbar

Beitrag von Marcus Breuer »

Und wieder einmal hallo Qt'ler,

ich probiere mich gerade an einer mobilen Anwendung, nachdem ich erst vor kurzem wegen eines Praktikums ins kalte Qt-Wasser geworfen wurde.

Mein Problem darin besteht, nachdem ich den Dialog ausgeführt habe und mir das, was dort in das LineEdit eingegeben wurde "geholt" habe, funktioniert das LineEdit im Hauptfenster nicht mehr.

Ich poste einfach mal alles. ich würde mich besonders darüber freuen, wenn Ihr mir vllt. auch eine geschicktere Art nennen könnt, einen Dialog auszuwerten, bzw für jede Kritik, die den Code betrifft, bin ich offen und dankbar.


Code: Alles auswählen

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QtGui/QMainWindow>
#include <QSystemDeviceInfo>
#include <QSet>
#include <QString>
#include <QStringList>


#include "produktmappe.h"

 QTM_USE_NAMESPACE

namespace Ui {
    class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT
public:
    enum ScreenOrientation {
        ScreenOrientationLockPortrait,
        ScreenOrientationLockLandscape,
        ScreenOrientationAuto
    };

    explicit MainWindow(QWidget *parent = 0);
    virtual ~MainWindow();

    void setOrientation(ScreenOrientation orientation);
    void showExpanded();

private:
    Ui::MainWindow *ui;
    QSystemDeviceInfo *deviceInfo;
    QSet<QString> list;
    QStringList products;
    produktmappe* mappe;

public slots:
    void function_add_to_list();
    void function_remove_from_list();
    void function_delete_list();
    void fill_products(int);



};

#endif // MAINWINDOW_H

Code: Alles auswählen

#include "mainwindow.h"
#include "ui_mainwindow.h"

#include <QtCore/QCoreApplication>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent), ui(new Ui::MainWindow),
      deviceInfo (NULL)
{
    ui->setupUi(this);

    mappe = new produktmappe;

    connect(ui->add_to_list, SIGNAL(clicked()),
                this, SLOT(function_add_to_list()));
    connect(ui->remove_from_list, SIGNAL(clicked()),
                this, SLOT(function_remove_from_list()));
    connect(ui->delete_list, SIGNAL(clicked()),
                this, SLOT(function_delete_list()));
    connect(ui->openProductmap, SIGNAL(clicked()),
            mappe, SLOT(exec()));
    connect(mappe, SIGNAL(finished(int)),
            this, SLOT(fill_products(int)));


}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::setOrientation(ScreenOrientation orientation)
{
#if defined(Q_OS_SYMBIAN)
    // If the version of Qt on the device is < 4.7.2, that attribute won't work
    if (orientation != ScreenOrientationAuto) {
        const QStringList v = QString::fromAscii(qVersion()).split(QLatin1Char('.'));
        if (v.count() == 3 && (v.at(0).toInt() << 16 | v.at(1).toInt() << 8 | v.at(2).toInt()) < 0x040702) {
            qWarning("Screen orientation locking only supported with Qt 4.7.2 and above");
            return;
        }
    }
#endif // Q_OS_SYMBIAN

    Qt::WidgetAttribute attribute;
    switch (orientation) {
#if QT_VERSION < 0x040702
    // Qt < 4.7.2 does not yet have the Qt::WA_*Orientation attributes
    case ScreenOrientationLockPortrait:
        attribute = static_cast<Qt::WidgetAttribute>(128);
        break;
    case ScreenOrientationLockLandscape:
        attribute = static_cast<Qt::WidgetAttribute>(129);
        break;
    default:
    case ScreenOrientationAuto:
        attribute = static_cast<Qt::WidgetAttribute>(130);
        break;
#else // QT_VERSION < 0x040702
    case ScreenOrientationLockPortrait:
        attribute = Qt::WA_LockPortraitOrientation;
        break;
    case ScreenOrientationLockLandscape:
        attribute = Qt::WA_LockLandscapeOrientation;
        break;
    default:
    case ScreenOrientationAuto:
        attribute = Qt::WA_AutoOrientation;
        break;
#endif // QT_VERSION < 0x040702
    };
    setAttribute(attribute, true);
}

void MainWindow::showExpanded()
{
#ifdef Q_OS_SYMBIAN
    showFullScreen();
#elif defined(Q_WS_MAEMO_5) || defined(Q_WS_MAEMO_6)
    showMaximized();
#else
    show();
#endif
}

void MainWindow::function_add_to_list() {
        QString tmp = ui->input->text();
        if(list.contains(tmp) || tmp.isEmpty()) {
           ui->input->clear();
       }
       else {
       list.insert(tmp);
       ui->listing->addItem(ui->input->text());
       ui->input->clear();
       }
}

void MainWindow::function_remove_from_list() {
    QListWidgetItem *ausgewaehltes_Element = ui->listing->currentItem();
        delete ausgewaehltes_Element;
}

void MainWindow::function_delete_list() {
    ui->listing->clear();
}

void MainWindow::fill_products(int val) {
    if(val == 99) {
    ui->listing->addItem(mappe->Element);


    }
}

Code: Alles auswählen

#ifndef PRODUKTMAPPE_H
#define PRODUKTMAPPE_H

#include <QDialog>

namespace Ui {
    class produktmappe;
}

class produktmappe : public QDialog
{
    Q_OBJECT

public:
    explicit produktmappe(QWidget *parent = 0);
    ~produktmappe();
    QString Element;

private:
    Ui::produktmappe *ui;

public slots:
    void get_Element();


};

#endif // PRODUKTMAPPE_H

Code: Alles auswählen

#include "produktmappe.h"
#include "ui_produktmappe.h"

produktmappe::produktmappe(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::produktmappe)
{
    ui->setupUi(this);

    connect(ui->saveProductmap, SIGNAL(clicked()),
            this, SLOT(get_Element()));
}

produktmappe::~produktmappe()
{
    delete ui;
}

void produktmappe::get_Element() {
    Element = ui->ProduktLineEdit->text();
    int result = 99;
    emit done(result);
}


Ich habe schon bisschen rumprobiert, allerdings blieb das LineEdit input nach dem Dialog nicht mehr ansprechbar. Ich kann nichts mehr hineinschreiben. In der Referenz zum LineEdit habe ich jedenfalls auch ichts mehr gefunden, was das hätte ändern können, jedenfalls aus meiner Sicht.

Viele Grüße
Antworten