I can tell what we did, we made a FileSystem C++ singleton that expose most file system file/url check, we made those check inside Qml javascript now. This way you can make callback and GUI logic into Qml. We expect C++ function to be call with valid argument all the time. Else we always return error (unexpected error, since the Qml code should have validate before making the call, this is a developer issue).
Side Note: We also have experiment with throw from C++ that get evaluate into Qml, it work, but it would be nice to have a proper keyword with throw type to indicate this and the exception get transfer to into Q_INVOKABLE. Would allow for better error handling. On Tue, Apr 26, 2016 at 5:58 AM, Sina Dogru <sinado...@gmail.com> wrote: > > > 2016-04-26 12:11 GMT+03:00 Shawn Rutledge <shawn.rutle...@qt.io>: > >> >> You shouldn’t need to do this. Just write onAccepted/onRejected handlers >> which call back to QML and/or C++ code as necessary. Is there some reason >> why that is difficult? >> >> Well the problem is (like I tried to explain on the email to Dmitry) > while using QFileDialog's and QMessageBox's static functions, program can > continue to flow from where those functions called. > > Let me please explain myself with a piece of code; > > void App::saveAs(const QString &path) > { > bool cont = true; > > while (cont) { > if (path.isEmpty()) > cont = false; > else { > QFileInfo fi = path; > > if (fi->exists()) { > int wantSave = QMessageBox::warning(nullptr, > tr("Warning"), tr("File %1 exists.\n" > "Do you wish to > overwrite it?").arg(fi->fileName()), > QMessageBox::Yes, > QMessageBox::No); > if (wantSave == QMessageBox::Yes) > cont = false; > else > path = QFileDialog::getSaveFileName(nullptr, tr("Save > As")); > } > else > cont = false; > } > } > if (!path.isEmpty()) > doc->save(url); > } > > For example, when the user press the save as tool button of the QML > ApplicationWindow, this slot is called onAccepted handler of the > FileDialog. But depending on the user input, application might need to do > something else. > > But I am not sure if I am violating the "UI and business logic seperation" > with this approach? > > _______________________________________________ > Interest mailing list > Interest@qt-project.org > http://lists.qt-project.org/mailman/listinfo/interest > >
_______________________________________________ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest