Kann nicht auf QLineEdit in Dialog von MainWinwow zugreifen
Verfasst: 12. März 2007 14:03
Hallo Leute,
Bitte entschuldigt erstmal die Frage - ich glaube sie ist eher C++ technischer Natur als direkt QT.
Aber ich hoffe ich gebt mir trotzdem einen Tipp.
Ich habe folgendes Problem:
Ich habe einen kleinen Suche- Dialog grafisch mit dem QT Deseginer (QT4) erstellt.
In meiner MainWindow Klasse rufe ich ihhn dan mittels einer Action auf.
Soweit ist das okay. Wenn der Dialog erscheint und ich auf den OK Button drücke, soll der SUCHE SLOT als Methode der MainWindow Klasse aufgerufen werden - das klappt auch.
ABER ich möchte nun den Text in der QLineEdit des Dialogs im SLOT SUCHEN im Mainwindow auslesen.
Hier sagt der Compiler dann er kennt searchEdit nicht (so heisst die QLineEdit als Objektname)
Ich versuchte es so:
void MainWindow::searchText()
{
QString searchString = searchEdit->text();
QTextDocument *document = textEdit->document();
QTextCursor newCursor(document);
while (!newCursor.isNull() && !newCursor.atEnd()) {
newCursor = document->find("", newCursor);
if (!newCursor.isNull()) {
newCursor.movePosition(QTextCursor::WordRight,
QTextCursor::KeepAnchor);
//newCursor.mergeCharFormat(QColor(Qt::green));
}
}
}
Eigentlich müsste der Compiler das Objekt doch so kenne, ich binde ja die search_dlg.h ein.
Könnt ihr mir bitte helfen. Wenn das geht, habe ich alles was ich zum Ferstigstellen des Programms brauche!!!
Herzlichen DANK an EUCH alle!!
Andreas
Hier noch die restlichen Auszüge des Dialogs:
ui_search_dlg.h:
/********************************************************************************
** Form generated from reading ui file 'search_dlg.ui'
**
** Created: Mon 12. Mar 13:31:43 2007
** by: Qt User Interface Compiler version 4.2.2
**
** WARNING! All changes made in this file will be lost when recompiling ui file!
********************************************************************************/
#ifndef UI_SEARCH_DLG_H
#define UI_SEARCH_DLG_H
#include <QtCore/QVariant>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QCheckBox>
#include <QtGui/QDialog>
#include <QtGui/QLabel>
#include <QtGui/QLineEdit>
#include <QtGui/QPushButton>
#include <QtGui/QRadioButton>
class Ui_search_dlg
{
public:
QCheckBox *checkBox;
QLabel *label;
QPushButton *okButton;
QPushButton *cancelButton;
QLineEdit *searchEdit;
QRadioButton *radioButton_2;
QRadioButton *radioButton;
void setupUi(QDialog *search_dlg)
{
search_dlg->setObjectName(QString::fromUtf8("search_dlg"));
QSizePolicy sizePolicy(static_cast<QSizePolicy::Policy>(0), static_cast<QSizePolicy::Policy>(0));
sizePolicy.setHorizontalStretch(0);
sizePolicy.setVerticalStretch(0);
sizePolicy.setHeightForWidth(search_dlg->sizePolicy().hasHeightForWidth());
search_dlg->setSizePolicy(sizePolicy);
checkBox = new QCheckBox(search_dlg);
checkBox->setObjectName(QString::fromUtf8("checkBox"));
checkBox->setGeometry(QRect(10, 80, 111, 18));
label = new QLabel(search_dlg);
label->setObjectName(QString::fromUtf8("label"));
label->setGeometry(QRect(10, 10, 101, 16));
okButton = new QPushButton(search_dlg);
okButton->setObjectName(QString::fromUtf8("okButton"));
okButton->setGeometry(QRect(10, 170, 61, 20));
cancelButton = new QPushButton(search_dlg);
cancelButton->setObjectName(QString::fromUtf8("cancelButton"));
cancelButton->setGeometry(QRect(80, 170, 61, 20));
searchEdit = new QLineEdit(search_dlg);
searchEdit->setObjectName(QString::fromUtf8("searchEdit"));
searchEdit->setGeometry(QRect(10, 40, 181, 20));
radioButton_2 = new QRadioButton(search_dlg);
radioButton_2->setObjectName(QString::fromUtf8("radioButton_2"));
radioButton_2->setGeometry(QRect(10, 140, 131, 18));
radioButton = new QRadioButton(search_dlg);
radioButton->setObjectName(QString::fromUtf8("radioButton"));
radioButton->setGeometry(QRect(10, 110, 83, 18));
retranslateUi(search_dlg);
QSize size(209, 198);
size = size.expandedTo(search_dlg->minimumSizeHint());
search_dlg->resize(size);
QObject::connect(okButton, SIGNAL(clicked()), search_dlg, SLOT(accept()));
QObject::connect(cancelButton, SIGNAL(clicked()), search_dlg, SLOT(reject()));
QObject::connect(cancelButton, SIGNAL(clicked()), search_dlg, SLOT(close()));
QMetaObject::connectSlotsByName(search_dlg);
} // setupUi
void retranslateUi(QDialog *search_dlg)
{
search_dlg->setWindowTitle(QApplication::translate("search_dlg", "Multi Edit :: Suchen", 0, QApplication::UnicodeUTF8));
checkBox->setText(QApplication::translate("search_dlg", "ganzen Ausdruck", 0, QApplication::UnicodeUTF8));
label->setText(QApplication::translate("search_dlg", "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal; text-decoration:none;\">\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:8pt;\"><span style=\" font-size:9pt; font-weight:600;\">Suchbegriff</span></p></body></html>", 0, QApplication::UnicodeUTF8));
okButton->setText(QApplication::translate("search_dlg", "OK", 0, QApplication::UnicodeUTF8));
cancelButton->setText(QApplication::translate("search_dlg", "Cancel", 0, QApplication::UnicodeUTF8));
radioButton_2->setText(QApplication::translate("search_dlg", "gesamtes Dokument", 0, QApplication::UnicodeUTF8));
radioButton->setText(QApplication::translate("search_dlg", "ab Cursor", 0, QApplication::UnicodeUTF8));
Q_UNUSED(search_dlg);
} // retranslateUi
};
namespace Ui {
class search_dlg: public Ui_search_dlg {};
} // namespace Ui
#endif // UI_SEARCH_DLG_H
search_dlg.h:
// Definition of the search_dlg class
// This file is part of the PS PP Multi Edit Component
// 2007 by Andreas Friede
#ifndef SEARCH_DLG_H
#define SEARCH_DLG_H
#include <QDialog>
#include "ui_search_dlg.h"
class search_dlg : public QDialog, private Ui::search_dlg
{
Q_OBJECT
public:
search_dlg(QWidget *parent = 0);
};
#endif
search_dlg.cpp
// Implementation of search_dlg
// This file is part of the PS PP Multi Edit Component
// 2007 by Andreas Friede
#include <QtGui>
#include "search_dlg.h"
#include "mainwindow.h"
search_dlg::search_dlg(QWidget *parent) : QDialog(parent)
{
setupUi(this);
connect(okButton, SIGNAL(clicked()),SLOT(MainWindow->searchText())); // okButton aus Dialog mit dem SLOT searchText()
// der Klasse MainWindow verbinden
}
Bitte entschuldigt erstmal die Frage - ich glaube sie ist eher C++ technischer Natur als direkt QT.
Aber ich hoffe ich gebt mir trotzdem einen Tipp.
Ich habe folgendes Problem:
Ich habe einen kleinen Suche- Dialog grafisch mit dem QT Deseginer (QT4) erstellt.
In meiner MainWindow Klasse rufe ich ihhn dan mittels einer Action auf.
Soweit ist das okay. Wenn der Dialog erscheint und ich auf den OK Button drücke, soll der SUCHE SLOT als Methode der MainWindow Klasse aufgerufen werden - das klappt auch.
ABER ich möchte nun den Text in der QLineEdit des Dialogs im SLOT SUCHEN im Mainwindow auslesen.
Hier sagt der Compiler dann er kennt searchEdit nicht (so heisst die QLineEdit als Objektname)
Ich versuchte es so:
void MainWindow::searchText()
{
QString searchString = searchEdit->text();
QTextDocument *document = textEdit->document();
QTextCursor newCursor(document);
while (!newCursor.isNull() && !newCursor.atEnd()) {
newCursor = document->find("", newCursor);
if (!newCursor.isNull()) {
newCursor.movePosition(QTextCursor::WordRight,
QTextCursor::KeepAnchor);
//newCursor.mergeCharFormat(QColor(Qt::green));
}
}
}
Eigentlich müsste der Compiler das Objekt doch so kenne, ich binde ja die search_dlg.h ein.
Könnt ihr mir bitte helfen. Wenn das geht, habe ich alles was ich zum Ferstigstellen des Programms brauche!!!
Herzlichen DANK an EUCH alle!!
Andreas
Hier noch die restlichen Auszüge des Dialogs:
ui_search_dlg.h:
/********************************************************************************
** Form generated from reading ui file 'search_dlg.ui'
**
** Created: Mon 12. Mar 13:31:43 2007
** by: Qt User Interface Compiler version 4.2.2
**
** WARNING! All changes made in this file will be lost when recompiling ui file!
********************************************************************************/
#ifndef UI_SEARCH_DLG_H
#define UI_SEARCH_DLG_H
#include <QtCore/QVariant>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QCheckBox>
#include <QtGui/QDialog>
#include <QtGui/QLabel>
#include <QtGui/QLineEdit>
#include <QtGui/QPushButton>
#include <QtGui/QRadioButton>
class Ui_search_dlg
{
public:
QCheckBox *checkBox;
QLabel *label;
QPushButton *okButton;
QPushButton *cancelButton;
QLineEdit *searchEdit;
QRadioButton *radioButton_2;
QRadioButton *radioButton;
void setupUi(QDialog *search_dlg)
{
search_dlg->setObjectName(QString::fromUtf8("search_dlg"));
QSizePolicy sizePolicy(static_cast<QSizePolicy::Policy>(0), static_cast<QSizePolicy::Policy>(0));
sizePolicy.setHorizontalStretch(0);
sizePolicy.setVerticalStretch(0);
sizePolicy.setHeightForWidth(search_dlg->sizePolicy().hasHeightForWidth());
search_dlg->setSizePolicy(sizePolicy);
checkBox = new QCheckBox(search_dlg);
checkBox->setObjectName(QString::fromUtf8("checkBox"));
checkBox->setGeometry(QRect(10, 80, 111, 18));
label = new QLabel(search_dlg);
label->setObjectName(QString::fromUtf8("label"));
label->setGeometry(QRect(10, 10, 101, 16));
okButton = new QPushButton(search_dlg);
okButton->setObjectName(QString::fromUtf8("okButton"));
okButton->setGeometry(QRect(10, 170, 61, 20));
cancelButton = new QPushButton(search_dlg);
cancelButton->setObjectName(QString::fromUtf8("cancelButton"));
cancelButton->setGeometry(QRect(80, 170, 61, 20));
searchEdit = new QLineEdit(search_dlg);
searchEdit->setObjectName(QString::fromUtf8("searchEdit"));
searchEdit->setGeometry(QRect(10, 40, 181, 20));
radioButton_2 = new QRadioButton(search_dlg);
radioButton_2->setObjectName(QString::fromUtf8("radioButton_2"));
radioButton_2->setGeometry(QRect(10, 140, 131, 18));
radioButton = new QRadioButton(search_dlg);
radioButton->setObjectName(QString::fromUtf8("radioButton"));
radioButton->setGeometry(QRect(10, 110, 83, 18));
retranslateUi(search_dlg);
QSize size(209, 198);
size = size.expandedTo(search_dlg->minimumSizeHint());
search_dlg->resize(size);
QObject::connect(okButton, SIGNAL(clicked()), search_dlg, SLOT(accept()));
QObject::connect(cancelButton, SIGNAL(clicked()), search_dlg, SLOT(reject()));
QObject::connect(cancelButton, SIGNAL(clicked()), search_dlg, SLOT(close()));
QMetaObject::connectSlotsByName(search_dlg);
} // setupUi
void retranslateUi(QDialog *search_dlg)
{
search_dlg->setWindowTitle(QApplication::translate("search_dlg", "Multi Edit :: Suchen", 0, QApplication::UnicodeUTF8));
checkBox->setText(QApplication::translate("search_dlg", "ganzen Ausdruck", 0, QApplication::UnicodeUTF8));
label->setText(QApplication::translate("search_dlg", "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal; text-decoration:none;\">\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:8pt;\"><span style=\" font-size:9pt; font-weight:600;\">Suchbegriff</span></p></body></html>", 0, QApplication::UnicodeUTF8));
okButton->setText(QApplication::translate("search_dlg", "OK", 0, QApplication::UnicodeUTF8));
cancelButton->setText(QApplication::translate("search_dlg", "Cancel", 0, QApplication::UnicodeUTF8));
radioButton_2->setText(QApplication::translate("search_dlg", "gesamtes Dokument", 0, QApplication::UnicodeUTF8));
radioButton->setText(QApplication::translate("search_dlg", "ab Cursor", 0, QApplication::UnicodeUTF8));
Q_UNUSED(search_dlg);
} // retranslateUi
};
namespace Ui {
class search_dlg: public Ui_search_dlg {};
} // namespace Ui
#endif // UI_SEARCH_DLG_H
search_dlg.h:
// Definition of the search_dlg class
// This file is part of the PS PP Multi Edit Component
// 2007 by Andreas Friede
#ifndef SEARCH_DLG_H
#define SEARCH_DLG_H
#include <QDialog>
#include "ui_search_dlg.h"
class search_dlg : public QDialog, private Ui::search_dlg
{
Q_OBJECT
public:
search_dlg(QWidget *parent = 0);
};
#endif
search_dlg.cpp
// Implementation of search_dlg
// This file is part of the PS PP Multi Edit Component
// 2007 by Andreas Friede
#include <QtGui>
#include "search_dlg.h"
#include "mainwindow.h"
search_dlg::search_dlg(QWidget *parent) : QDialog(parent)
{
setupUi(this);
connect(okButton, SIGNAL(clicked()),SLOT(MainWindow->searchText())); // okButton aus Dialog mit dem SLOT searchText()
// der Klasse MainWindow verbinden
}