summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/corelib/tools/customtype/message.cpp3
-rw-r--r--examples/opengl/hellowindow/hellowindow.cpp16
-rw-r--r--examples/opengl/hellowindow/hellowindow.h4
-rw-r--r--examples/opengl/hellowindow/main.cpp18
-rw-r--r--examples/widgets/gestures/imagegestures/imagewidget.cpp4
5 files changed, 34 insertions, 11 deletions
diff --git a/examples/corelib/tools/customtype/message.cpp b/examples/corelib/tools/customtype/message.cpp
index c470ab116e..eb8befc36f 100644
--- a/examples/corelib/tools/customtype/message.cpp
+++ b/examples/corelib/tools/customtype/message.cpp
@@ -65,7 +65,8 @@ Message::Message(const QString &body, const QStringList &headers)
//! [custom type streaming operator]
QDebug operator<<(QDebug dbg, const Message &message)
{
- QStringList pieces = message.body().split("\r\n", QString::SkipEmptyParts);
+ const QString body = message.body();
+ QVector<QStringRef> pieces = body.splitRef("\r\n", QString::SkipEmptyParts);
if (pieces.isEmpty())
dbg.nospace() << "Message()";
else if (pieces.size() == 1)
diff --git a/examples/opengl/hellowindow/hellowindow.cpp b/examples/opengl/hellowindow/hellowindow.cpp
index 57eb111edb..ac5bfea280 100644
--- a/examples/opengl/hellowindow/hellowindow.cpp
+++ b/examples/opengl/hellowindow/hellowindow.cpp
@@ -56,9 +56,14 @@ Renderer::Renderer(const QSurfaceFormat &format, Renderer *share, QScreen *scree
if (share)
m_context->setShareContext(share->m_context);
m_context->create();
+
+ m_backgroundColor = QColor::fromRgbF(0.1f, 0.1f, 0.2f, 1.0f);
+ m_backgroundColor.setRed(qrand() % 64);
+ m_backgroundColor.setGreen(qrand() % 128);
+ m_backgroundColor.setBlue(qrand() % 256);
}
-HelloWindow::HelloWindow(const QSharedPointer<Renderer> &renderer)
+HelloWindow::HelloWindow(const QSharedPointer<Renderer> &renderer, QScreen *screen)
: m_colorIndex(0), m_renderer(renderer)
{
setSurfaceType(QWindow::OpenGLSurface);
@@ -67,6 +72,8 @@ HelloWindow::HelloWindow(const QSharedPointer<Renderer> &renderer)
setGeometry(QRect(10, 10, 640, 480));
setFormat(renderer->format());
+ if (screen)
+ setScreen(screen);
create();
@@ -147,7 +154,7 @@ void Renderer::render()
f->glViewport(0, 0, viewSize.width() * surface->devicePixelRatio(), viewSize.height() * surface->devicePixelRatio());
f->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- f->glClearColor(0.1f, 0.1f, 0.2f, 1.0f);
+ f->glClearColor(m_backgroundColor.redF(), m_backgroundColor.greenF(), m_backgroundColor.blueF(), m_backgroundColor.alphaF());
f->glFrontFace(GL_CW);
f->glCullFace(GL_FRONT);
f->glEnable(GL_CULL_FACE);
@@ -180,8 +187,13 @@ void Renderer::render()
QTimer::singleShot(0, this, SLOT(render()));
}
+Q_GLOBAL_STATIC(QMutex, initMutex)
+
void Renderer::initialize()
{
+ // Threaded shader compilation can confuse some drivers. Avoid it.
+ QMutexLocker lock(initMutex());
+
QOpenGLShader *vshader = new QOpenGLShader(QOpenGLShader::Vertex, this);
vshader->compileSourceCode(
"attribute highp vec4 vertex;"
diff --git a/examples/opengl/hellowindow/hellowindow.h b/examples/opengl/hellowindow/hellowindow.h
index 6a6fa275e2..cba4b34db6 100644
--- a/examples/opengl/hellowindow/hellowindow.h
+++ b/examples/opengl/hellowindow/hellowindow.h
@@ -90,12 +90,14 @@ private:
int m_currentWindow;
QMutex m_windowLock;
+
+ QColor m_backgroundColor;
};
class HelloWindow : public QWindow
{
public:
- explicit HelloWindow(const QSharedPointer<Renderer> &renderer);
+ explicit HelloWindow(const QSharedPointer<Renderer> &renderer, QScreen *screen = 0);
QColor color() const;
void updateColor();
diff --git a/examples/opengl/hellowindow/main.cpp b/examples/opengl/hellowindow/main.cpp
index 62b6bfca3f..e7ad9722c2 100644
--- a/examples/opengl/hellowindow/main.cpp
+++ b/examples/opengl/hellowindow/main.cpp
@@ -50,7 +50,9 @@ int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
+ // Some platforms can only have one window per screen. Therefore we need to differentiate.
const bool multipleWindows = QGuiApplication::arguments().contains(QStringLiteral("--multiple"));
+ const bool multipleScreens = QGuiApplication::arguments().contains(QStringLiteral("--multiscreen"));
QScreen *screen = QGuiApplication::primaryScreen();
@@ -93,12 +95,13 @@ int main(int argc, char *argv[])
windowC->setTitle(QStringLiteral("Thread B - Context B"));
windowC->setVisible(true);
windows.prepend(windowC);
-
+ }
+ if (multipleScreens) {
for (int i = 1; i < QGuiApplication::screens().size(); ++i) {
QScreen *screen = QGuiApplication::screens().at(i);
QSharedPointer<Renderer> renderer(new Renderer(format, rendererA.data(), screen));
- renderThread = new QThread;
+ QThread *renderThread = new QThread;
renderer->moveToThread(renderThread);
renderThreads.prepend(renderThread);
@@ -107,8 +110,7 @@ int main(int argc, char *argv[])
QSize windowSize = screenGeometry.size() * 0.8;
- HelloWindow *window = new HelloWindow(renderer);
- window->setScreen(screen);
+ HelloWindow *window = new HelloWindow(renderer, screen);
window->setGeometry(QRect(center, windowSize).translated(-windowSize.width() / 2, -windowSize.height() / 2));
QChar id = QChar('B' + i);
@@ -123,10 +125,16 @@ int main(int argc, char *argv[])
renderThreads.at(i)->start();
}
+ // Quit after 10 seconds. For platforms that do not have windows that are closeable.
+ if (QCoreApplication::arguments().contains(QStringLiteral("--timeout")))
+ QTimer::singleShot(10000, qGuiApp, SLOT(quit()));
+
const int exitValue = app.exec();
- for (int i = 0; i < renderThreads.size(); ++i)
+ for (int i = 0; i < renderThreads.size(); ++i) {
+ renderThreads.at(i)->quit(); // some platforms may not have windows to close so ensure quit()
renderThreads.at(i)->wait();
+ }
qDeleteAll(windows);
qDeleteAll(renderThreads);
diff --git a/examples/widgets/gestures/imagegestures/imagewidget.cpp b/examples/widgets/gestures/imagegestures/imagewidget.cpp
index 57c2af4502..81783f211d 100644
--- a/examples/widgets/gestures/imagegestures/imagewidget.cpp
+++ b/examples/widgets/gestures/imagegestures/imagewidget.cpp
@@ -108,7 +108,7 @@ void ImageWidget::mouseDoubleClickEvent(QMouseEvent *)
//! [gesture event handler]
bool ImageWidget::gestureEvent(QGestureEvent *event)
{
- qCDebug(lcExample) << "gestureEvent():" << event->gestures().size();
+ qCDebug(lcExample) << "gestureEvent():" << event;
if (QGesture *swipe = event->gesture(Qt::SwipeGesture))
swipeTriggered(static_cast<QSwipeGesture *>(swipe));
else if (QGesture *pan = event->gesture(Qt::PanGesture))
@@ -132,7 +132,7 @@ void ImageWidget::panTriggered(QPanGesture *gesture)
}
#endif
QPointF delta = gesture->delta();
- qCDebug(lcExample) << "panTriggered():" << delta;
+ qCDebug(lcExample) << "panTriggered():" << gesture;
horizontalOffset += delta.x();
verticalOffset += delta.y();
update();