Dialog input form validation
-
wrote on 17 Apr 2025, 06:18 last edited by
I have a dialog window with standard buttons and different input fields (image upload, name, price, etc). Each field has it's validator, such as int validator, double validator, regex validator. While any field has an inacceptable input the OK button is disabled (enabled if all fields have acceptable values)
I also have unique constraints in database, then I created Q_INVOKABLE method that checks whether name and chosen image are unique. I need to include these unique validations in QML together with other above mentioned validations.
What is the best practice workflow generally? Is there a straightforward way to validate input forms both in place and with DB response?
-
-
wrote 11 days ago last edited by
Use client-side validation in QML (e.g., IntValidator, DoubleValidator) for immediate input checks. After that, call a C++ Q_INVOKABLE method to perform server-side validation (e.g., check for unique name/image in the database). Ensure the database check is asynchronous to avoid blocking the UI, and provide feedback if the check fails (e.g., show an error message if the name/image isn't unique). This ensures both local and database validation while maintaining a smooth user experience.
2/2