main.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #include <QtGui/QApplication>
  2. #include <QDeclarativeContext>
  3. #include "qmlapplicationviewer.h"
  4. #include "filterproxymodel.h"
  5. #include "purchasableitembase.h"
  6. #include <QFile>
  7. #include <QTextStream>
  8. void myMessageHandler(QtMsgType type, const char *msg)
  9. {
  10. QString txt;
  11. switch (type) {
  12. case QtDebugMsg:
  13. txt = QString("Debug: %1").arg(msg);
  14. break;
  15. case QtWarningMsg:
  16. txt = QString("Warning: %1").arg(msg);
  17. break;
  18. case QtCriticalMsg:
  19. txt = QString("Critical: %1").arg(msg);
  20. break;
  21. case QtFatalMsg:
  22. txt = QString("Fatal: %1").arg(msg);
  23. abort();
  24. }
  25. QFile outFile("c:/data/TryAndBuy.log");
  26. outFile.open(QIODevice::WriteOnly | QIODevice::Append);
  27. QTextStream ts(&outFile);
  28. ts << txt << endl;
  29. }
  30. int main(int argc, char *argv[])
  31. {
  32. QApplication app(argc, argv);
  33. //qInstallMsgHandler(myMessageHandler);
  34. QmlApplicationViewer viewer;
  35. viewer.setOrientation(QmlApplicationViewer::ScreenOrientationAuto);
  36. //connecting model to QML
  37. FilterProxyModel model;
  38. viewer.rootContext()->setContextProperty("catalogModel", &model);
  39. //create filters and connect them to QML
  40. ItemsToBuyModel itemsToBuyModel(*model.sourceModel());
  41. viewer.rootContext()->setContextProperty("itemsToBuyModel", &itemsToBuyModel);
  42. ItemsYouHaveModel itemsBoughtModel(*model.sourceModel());
  43. viewer.rootContext()->setContextProperty("itemsBoughtModel", &itemsBoughtModel);
  44. viewer.setMainQmlFile(QLatin1String("qml/main.qml"));
  45. viewer.showExpanded();
  46. return app.exec();
  47. }