August 2018
Intermediate to advanced
534 pages
11h 21m
English
We deserve something better than an untitled task. The user needs to define its name when created. The easiest path would be to display a dialog where the user can input the task name. Fortunately, Qt offers us a very configurable dialog that fits perfectly in addTask():
#include <QInputDialog>
...
void MainWindow::addTask()
{
bool ok;
QString name = QInputDialog::getText(this,
tr("Add task"),
tr("Task name"),
QLineEdit::Normal,
tr("Untitled task"), &ok);
if (ok && !name.isEmpty()) {
qDebug() << "Adding new task";
Task* task = new Task(name);
mTasks.append(task);
ui->tasksLayout->addWidget(task);
}
}
The QinputDialog::getText function is a static blocking function that displays the dialog. When the user validates/cancels the ...
Read now
Unlock full access