0
我在我的MainWindow中發出一個信號,以便在行編輯中發出一個數字。當我點擊一個按鈕打開對話框時,我希望將該編號複製到對話框中的行編輯中。我無法連接它。我可以看到qDebug發出的信號。我連接錯了還是錯了嗎?我嘗試了很多方法。這裏是我的代碼片段。如何將信號從MainWindow連接到對話框中的插槽
主窗口
//My MainWindow
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) {
ui->setupUi(this);
//This is the number I am trying to send to the dialog
ui->checkingAmount->setText(QString::number(1000.00, 'f', 2));
ui->checkingAmount->setReadOnly(true);
}
//Emit the data here
void MainWindow::on_transferButton_clicked() {
transferWindow = new TransferWindow(this);
transferWindow->show();
//trying to emit the data
QString data =ui->checkingAmount->text();
emit shareCheckingData(data);
qDebug()<<"emitting mainwin amount";
}
對話框
//My Dialog
TransferWindow::TransferWindow(QWidget *parent) : QDialog(parent),ui(new Ui::TransferWindow) {
ui->setupUi(this);
//I have tried several variations of this
//mainWindow = new MainWindow();
connect(mainWindow, SIGNAL(shareCheckingData(QString)),this, SLOT(getAmountFromMainWin(QString)));
}
//Here is the connecting slot to get the data from main window
void TransferWindow::getAmountFromMainWin(QString n) {
float CheckTotal = n.toFloat();
ui->checkingAmount->setReadOnly(true);
ui->checkingAmount->setText(QString::number(CheckTotal));
qDebug()<<"setting amount";
}
我如何能得到這個連接?我閱讀了很多帖子,但沒有解決問題。謝謝。
謝謝eyllanesc。你曾多次幫助過我。我很感激。 – equati0n