Answer the question
In order to leave comments, you need to log in
How to pass data between forms and change them?
I am making a reminder program like Birthday in QT. I don't understand how to implement "edit" and "add" buttons for tasks. By pressing the "add" button, a second form opens in which I enter the task, I press OK and it is transferred to the main form and displayed on the screen. And by pressing the "change" button, the selected object (or a pointer to it, I don't know how to do it all) is also transferred to the second form and edited there, after which we return it to the main form. mainwindow.cpp
void MainWindow::on_pushButton_add_clicked()
{ Script stakan;
Dialog *add = new Dialog(stakan, this);
add->exec();
Script stakanadd = add->stakan;
if (add->g==true){
korobka.append(stakan);
}
else {
}
add->deleteLater();
korobka.append(stakan);
}
void MainWindow::on_pushButton_edit_clicked()
{
Script stk;
stk.SetText(ui->Today->currentItem()->text());
QVariant data=ui->Today->currentItem()->data(Qt::UserRole);
stk.setData(data.toDate());
Dialog *sohr = new Dialog(stk, this);
sohr->exec();
Script stakanedit = sohr->stakan;
if (sohr->g==true){
korobka.append(stakanedit);
}
else {
}
sohr->deleteLater();
korobka.append(stakanedit);
}
void Dialog::on_button_changeValue_accepted()
{
g=true;
Dialog::close();
}
void Dialog::on_button_changeValue_rejected()
{
g=false;
Dialog::close();
}
class Script
{
public:
Script();
void SetText(const QString &str);
QString GetText();
QDate getData() const;
void setData(const QDate &value);
private:
QString text;
QDate data;
};
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question