我有一个单独实现的QWidget (keyboardW)
和一个QDialog (pacsD)
,如果我在我的QMainWindow
上触发QPushButton
,两者都在我的QMainWindow
上同时打开/表示。keyboardW
表示虚拟键盘,pacsD
包含一些QLineEdit's
,如果用户在键盘上写入某些内容,则应填充这些。我实现了如下功能。问题是:如果keyboardW
发出带有QString
的信号,则pacsD
类中的插槽transmitOutputTextSlot()
接收到具有正确内容的信号。但是文本没有在lineEdit
上表示。我尝试了setFocus()
和repaint()
功能。没有成功。
键盘W.h
namespace int::Mic::Manager {
class PacsD;
class KeyboardW: public QObject, public Ui::keyboardW
{
Q_OBJECT
public:
KeyboardW(QWidget *parent= 0);
~KeyboardW();
QWidget *getKeyboardW(){ return m_KeyboardW; }
signals:
void transmitOutputTextSignal(QString);
private slots:
void setTextSlot();
private:
PacsD *m_PacsD;
QPointer<QWidget> m_KeyboardW;
void init();
QString m_OutputText;
};
}
键盘W.cpp
namespace int::Mic::Manager {
KeyboardW::KeyboardW(QWidget *parent) : QObject(parent)
{
m_KeyboardW = QPointer<QWidget>(new QWidget());
setupUi(m_KeyboardW);
init();
}
void KeyboardW::init()
{
m_PacsD = new PacsD;
connect(this, SIGNAL(transmitOutputTextSignal(QString)), m_PacsD, SLOT(transmitOutputTextSlot(QString)));
}
void KeyboardW::setTextSlot()
{
// m_OutputText contains what I have written on the virtual keyboard
emit transmitOutputTextSignal(m_OutputText);
}
}
PacsD.h
#pragma once
namespace int::Mic::Manager {
class PacsD: public QObject, public Ui::pacsD
{
Q_OBJECT
public:
PacsD(QDialog *parent= 0);
~PacsD();
QDialog *getPacsD(){ return m_PacsD; }
public slots:
void transmitOutputTextSlot(QString);
private:
QPointer<QDialog> m_PacsD;
};
}
PacsD.cpp
namespace int::Mic::Manager {
PacsD::PacsD(QDialog *parent) : QObject(parent)
{
m_PacsD = QPointer<QDialog>(new QDialog());
setupUi(m_PacsD);
}
void PacsD::transmitOutputTextSlot(QString text)
{
nameLineEdit->setText(text);
qDebug()<<"nameLineEdit Text: "<<text;
// The content of the LineEdit is correcly given
QString getTransmittedText= nameLineEdit->text();
qDebug()<<"getTransmittedText: "<<getTransmittedText;
}
}
nameLineEdit->setText() 是否在其他地方工作(即在构造函数中)?您的标签中是否已在 *.ui 文件中设置了文本?