我嘗試了很多事情,並且一整天都沒有看到真正的進展。即使在我輸入這個問題時,我也經歷了所有堆棧溢出建議。 我的目標是?讓dialog2向dialog1發出一個信號來調用dialog1中的函數,以加載/更新QWidgetTable。 在dialog2(no Buttons)中,keyPressEvent(F4)打開一個文件,將文本保存在一個lineEdit中,並保存到文件中。在流出完成之後,流將被刷新,文件關閉並且lineEdit字段被重置,以便您可以根據需要輸入更多內容。所有這些都很完美,部分歸功於這個論壇。 但是,作爲dialog2只不過是一個messageBox的大小,你仍然可以在它後面看到dialog1,而tableWidget不會用你剛剛保存到文件中的東西來更新自己。這對用戶來說看起來很奇怪。 這是我在哪裏...qt dialog2連接dialog1更新QtableWidget
connect(this->ui->lineEdit,SIGNAL(textChanged(QString)),dialog1,SLOT(loadTable()));
(this)會是dialog2。 它不編譯。我知道我在這裏錯過了一些東西。如果小部件位於自己的「窗體」/「窗口」內,則信號和插槽相對容易。
任何幫助將不勝感激。
Dialog1::Dialog1(QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog1)
{
setWindowFlags(Qt::Widget | Qt::FramelessWindowHint);//Frameless
ui->setupUi(this);
//Move the dialog away from the center
this->setGeometry(0,0,this->width(),this->height());
//Put the dialog in the screen center
const QRect screen = QApplication::desktop()->screenGeometry();
this->move(screen.center() - this->rect().center());
loadTable();
}
Dialog2::Dialog2(QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog2)
{
setWindowFlags(Qt::Widget | Qt::FramelessWindowHint);//Frameless
ui->setupUi(this);
//Move the dialog away from the center
this->setGeometry(0,0,this->width(),this->height());
//Put the dialog in the screen center
const QRect screen = QApplication::desktop()->screenGeometry();
this->move(screen.center() - this->rect().center());
connect(ui->lineEdit,SIGNAL(textChanged(QString)),&Dialog1,SLOT(loadTable()));
}
我不明白。
你說這不編譯 - 你可以讓我們知道什麼樣的錯誤,編譯器給你? – docsteer
如果dialog1不是指針,請在其之前添加&運算符。 connect(this-> ui-> lineEdit,SIGNAL(textChanged(QString)),&dialog1,SLOT(loadTable())); 或 connect(this-> ui-> lineEdit,SIGNAL(textChanged(QString)),ui-> dialog1,SLOT(loadTable())); –
這裏是錯誤:C:\ ... \ ... \ ... \ dialog2.cpp:29:錯誤:預期的主要表達式在第一個建議的','標記之前。 – Hank