Skip to content

Commit

Permalink
QT_NO_CAST_FROM_ASCI build error part3: examples
Browse files Browse the repository at this point in the history
  • Loading branch information
wang-bin committed Aug 8, 2015
1 parent 665f1d9 commit 84ed2aa
Show file tree
Hide file tree
Showing 47 changed files with 648 additions and 620 deletions.
62 changes: 31 additions & 31 deletions examples/QMLPlayer/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,86 +36,86 @@
int main(int argc, char *argv[])
{
QOptions options(get_common_options());
options.add("QMLPlayer options")
("scale", 1.0, "scale of graphics context. 0: auto")
options.add(QLatin1String("QMLPlayer options"))
("scale", 1.0, QLatin1String("scale of graphics context. 0: auto"))
;
options.parse(argc, argv);
if (options.value("help").toBool()) {
if (options.value(QLatin1String("help")).toBool()) {
options.print();
return 0;
}

QGuiApplication app(argc, argv);
QDir::setCurrent(qApp->applicationDirPath());
qDebug() << "arguments======= " << app.arguments();
set_opengl_backend(options.option("gl").value().toString(), app.arguments().first());
load_qm(QStringList() << "QMLPlayer", options.value("language").toString());
set_opengl_backend(options.option(QStringLiteral("gl")).value().toString(), app.arguments().first());
load_qm(QStringList() << QStringLiteral("QMLPlayer"), options.value(QStringLiteral("language")).toString());
QtQuick2ApplicationViewer viewer;
QString binDir = qApp->applicationDirPath();
if (binDir.endsWith(".app/Contents/MacOS")) {
binDir.remove(".app/Contents/MacOS");
binDir = binDir.left(binDir.lastIndexOf("/"));
if (binDir.endsWith(QLatin1String(".app/Contents/MacOS"))) {
binDir.remove(QLatin1String(".app/Contents/MacOS"));
binDir = binDir.left(binDir.lastIndexOf(QLatin1String("/")));
}
QQmlEngine *engine = viewer.engine();
if (!engine->importPathList().contains(binDir))
engine->addImportPath(binDir);
qDebug() << engine->importPathList();
engine->rootContext()->setContextProperty("PlayerConfig", &Config::instance());
engine->rootContext()->setContextProperty(QStringLiteral("PlayerConfig"), &Config::instance());
qDebug(">>>>>>>>devicePixelRatio: %f", qApp->devicePixelRatio());
QScreen *sc = app.primaryScreen();
qDebug() << "dpi phy: " << sc->physicalDotsPerInch() << ", logical: " << sc->logicalDotsPerInch() << ", dpr: " << sc->devicePixelRatio()
<< "; vis rect:" << sc->virtualGeometry();
// define a global var for js and qml
engine->rootContext()->setContextProperty("screenPixelDensity", qApp->primaryScreen()->physicalDotsPerInch()*qApp->primaryScreen()->devicePixelRatio());
engine->rootContext()->setContextProperty(QStringLiteral("screenPixelDensity"), qApp->primaryScreen()->physicalDotsPerInch()*qApp->primaryScreen()->devicePixelRatio());
qreal r = sc->physicalDotsPerInch()/sc->logicalDotsPerInch();
if (std::isinf(r) || std::isnan(r))
#if defined(Q_OS_ANDROID)
r = 2.0;
#else
r = 1.0;
#endif
float sr = options.value("scale").toFloat();
float sr = options.value(QStringLiteral("scale")).toFloat();
#if defined(Q_OS_ANDROID)
sr = r;
if (sr > 2.0)
sr = 2.0; //FIXME
#endif
if (qFuzzyIsNull(sr))
sr = r;
engine->rootContext()->setContextProperty("scaleRatio", sr);
QString qml = "qml/QMLPlayer/main.qml";
if (QFile(qApp->applicationDirPath() + "/" + qml).exists())
qml.prepend(qApp->applicationDirPath() + "/");
engine->rootContext()->setContextProperty(QStringLiteral("scaleRatio"), sr);
QString qml = QStringLiteral("qml/QMLPlayer/main.qml");
if (QFile(qApp->applicationDirPath() + QLatin1String("/") + qml).exists())
qml.prepend(qApp->applicationDirPath() + QLatin1String("/"));
else
qml.prepend("qrc:///");
qml.prepend(QLatin1String("qrc:///"));
viewer.setMainQmlFile(qml);
viewer.show();
QOption op = options.option("width");
QOption op = options.option(QStringLiteral("width"));
if (op.isSet())
viewer.setWidth(op.value().toInt());
op = options.option("height");
op = options.option(QStringLiteral("height"));
if (op.isSet())
viewer.setHeight(op.value().toInt());
op = options.option("x");
op = options.option(QStringLiteral("x"));
if (op.isSet())
viewer.setX(op.value().toInt());
op = options.option("y");
op = options.option(QStringLiteral("y"));
if (op.isSet())
viewer.setY(op.value().toInt());
if (options.value("fullscreen").toBool())
if (options.value(QStringLiteral("fullscreen")).toBool())
viewer.showFullScreen();

viewer.setTitle("QMLPlayer based on QtAV. [email protected]");
viewer.setTitle(QStringLiteral("QMLPlayer based on QtAV. [email protected]"));
/*
* find root item, then root.init(argv). so we can deal with argv in qml
*/
#if 1
QString json = app.arguments().join("\",\"");
json.prepend("[\"").append("\"]");
json.replace("\\", "/"); //FIXME
QString json = app.arguments().join(QStringLiteral("\",\""));
json.prepend(QLatin1String("[\"")).append(QLatin1String("\"]"));
json.replace(QLatin1String("\\"), QLatin1String("/")); //FIXME
QMetaObject::invokeMethod(viewer.rootObject(), "init", Q_ARG(QVariant, json));
//#else
QObject *player = viewer.rootObject()->findChild<QObject*>("player");
QObject *player = viewer.rootObject()->findChild<QObject*>(QStringLiteral("player"));
if (player) {
AppEventFilter *ae = new AppEventFilter(player, player);
qApp->installEventFilter(ae);
Expand All @@ -128,17 +128,17 @@ int main(int argc, char *argv[])
.toString();
#endif
if (app.arguments().size() > 1) {
file = options.value("file").toString();
file = options.value(QStringLiteral("file")).toString();
if (file.isEmpty()) {
if (argc > 1 && !app.arguments().last().startsWith('-') && !app.arguments().at(argc-2).startsWith('-'))
if (argc > 1 && !app.arguments().last().startsWith(QLatin1Char('-')) && !app.arguments().at(argc-2).startsWith(QLatin1Char('-')))
file = app.arguments().last();
}
}
qDebug() << "file: " << file;
if (player && !file.isEmpty()) {
if (!file.startsWith("file:") && QFile(file).exists())
file.prepend("file:"); //qml use url and will add qrc: if no scheme
file.replace("\\", "/"); //qurl
if (!file.startsWith(QLatin1String("file:")) && QFile(file).exists())
file.prepend(QLatin1String("file:")); //qml use url and will add qrc: if no scheme
file.replace(QLatin1String("\\"), QLatin1String("/")); //qurl
QMetaObject::invokeMethod(player, "play", Q_ARG(QUrl, QUrl(file)));
}
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class QtQuick2ApplicationViewerPrivate

QString QtQuick2ApplicationViewerPrivate::adjustPath(const QString &path)
{
if (path.startsWith("qrc:"))
if (path.startsWith(QLatin1String("qrc:")))
return path;
#if defined(Q_OS_IOS)
if (!QDir::isAbsolutePath(path))
Expand Down Expand Up @@ -66,9 +66,9 @@ QtQuick2ApplicationViewer::~QtQuick2ApplicationViewer()

void QtQuick2ApplicationViewer::setMainQmlFile(const QString &file)
{
if (file.startsWith("qrc:")) {
if (file.startsWith(QLatin1String("qrc:"))) {
d->mainQmlFile = file;
setSource(d->mainQmlFile);
setSource(QUrl(d->mainQmlFile));
return;
}
d->mainQmlFile = QtQuick2ApplicationViewerPrivate::adjustPath(file);
Expand All @@ -77,7 +77,7 @@ void QtQuick2ApplicationViewer::setMainQmlFile(const QString &file)
#else
QUrl qmlUrl(QUrl::fromLocalFile(d->mainQmlFile));
#endif
if (d->mainQmlFile.startsWith("qrc:/")) {
if (d->mainQmlFile.startsWith(QLatin1String("qrc:/"))) {
qmlUrl = QUrl(d->mainQmlFile);
}
setSource(qmlUrl);
Expand Down
2 changes: 1 addition & 1 deletion examples/audiopipeline/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ static const int kBufferSize = 1024;
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
qDebug() << "usage: " << a.applicationFilePath().split("/").last().append(" url");
qDebug() << QLatin1String("usage: ") << a.applicationFilePath().split(QLatin1String("/")).last().append(QLatin1String(" url"));
if (a.arguments().size() < 2)
return 0;
QScopedPointer<AudioOutput> ao(new AudioOutput());
Expand Down
Loading

0 comments on commit 84ed2aa

Please sign in to comment.