Reputation: 59
I m developing one app for contact reading . In contact adding page I have created some textfields like first name n last name , phone number etc. And I have created one ActionItem to save or create contact . like this
acceptAction: ActionItem {
title: (_contactRead.contactEditor.mode == ContactEditor.CreateMode ? qsTr ("Create" ) : qsTr ("Save"))
onTriggered: {
_contactRead.contactEditor.saveContact()
navigationPane.pop()
}
}
I want to display pop up (dialog box or toast) when we click on save or create contact. I tried to add open() in onTriggered but confused how and where to create dialog box.
Please help me out....
Upvotes: 0
Views: 288
Reputation: 11217
use --> alert(tr("contact saved"));
refer following sample
-----------qml--------------
Button {
horizontalAlignment: HorizontalAlignment.Center
text: qsTr("Update")
onClicked: {
_app.updateRecord(idUpdateTextField.text, firstNameUpdateTextField.text, lastNameUpdateTextField.text);
}
}
-----------------cpp file-------------------
bool App::updateRecord(const QString &customerID, const QString &firstName, const QString &lastName)
{
bool intConversionGood = false;
const int customerIDKey = customerID.toInt(&intConversionGood);
if (!intConversionGood) {
alert(tr("You must provide valid integer key."));
return false;
}
QSqlDatabase database = QSqlDatabase::database();
QSqlQuery query(database);
const QString sqlCommand = "UPDATE customers "
" SET firstName = :firstName, lastName = :lastName"
" WHERE customerID = :customerID";
query.prepare(sqlCommand);
query.bindValue(":firstName", firstName);
query.bindValue(":lastName", lastName);
query.bindValue(":customerID", customerIDKey);
bool updated = false;
if (query.exec()) {
if (query.numRowsAffected() > 0) {
alert(tr("Customer with id=%1 was updated.").arg(customerID));
updated = true;
} else {
alert(tr("Customer with id=%1 was not found.").arg(customerID));
}
} else {
alert(tr("SQL error: %1").arg(query.lastError().text()));
}
database.close();
return updated;
}
Upvotes: 1