Loading and unloading textures crashes the system - qt

While debugging an application written in Qt using OpenGL ES 2.0 on a Linux embedded ARM platform, I noticed that when repeatedly loading and unloading textures, the embedded platform I'm working on started to behave strangely. I therefore wrote a simple test code to stress the OpenGL library:
main.cpp
#include <QApplication>
#include "mainwidget.h"
int main(int argc, char** argv)
{
QApplication a(argc, argv);
MainWidget widget;
widget.showFullScreen();
return a.exec();
}
and mainwidget.h:
#include <QElapsedTimer>
#include <QTimer>
#include "mainwidget.h"
MainWidget::MainWidget(QWidget *parent) :
QGLWidget(parent)
{
makeCurrent();
QTimer* t = new QTimer();
t->setSingleShot(false);
t->setInterval(10);
connect(t, SIGNAL(timeout()), this, SLOT(textureLoadingTest()));
t->start();
}
void MainWidget::textureLoadingTest()
{
QImage image(256, 512, QImage::Format_ARGB32);
image.fill(Qt::red);
QElapsedTimer timer;
timer.start();
GLuint code = bindTexture(image);
qDebug("Texture loaded in %lldms to code = %u.", timer.elapsed(), code);
deleteTexture(code);
}
This code seems to completely crash the system after 20/30 thousands textures.
Is this a bug in the test code or a system problem?

Related

FFmpeg on Qt Creator

I have got FFmpeg compiled using MSYS2. I have a strange issue that appeared only recently.the app crashes.
This is my main file:
#include "mainwindow.h"
#include <QApplication>
#include <QDebug>
extern "C" {
#include <libavdevice/avdevice.h>
#include <libavformat/avformat.h>
#include <libavutil/avutil.h>
#include <libavcodec/avcodec.h>
}
int main(int argc, char *argv[])
{
//qDebug() << av_version_info();
// avdevice_register_all();
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
The program runs but crashes if I call 'avdevice_register_all()' and others FFmpeg functions,but only call 'av_version_info()' is runs, not crashes.
I don't really know how to solve this?
I have already tried to use google solving the problem,but no result.

How to play video by internet link with QT using QMediaPlayer object

I want to play video using QMediaplayer with internet link. I tried to do this by passing internet link to "setMedia" function but error occured:
"DirectShowPlayerService::doRender: Unresolved error code 80040218"
Example Code is:
#include "mainwindow.h"
#include <QApplication>
#include <QMediaPlayer>
#include <QVideoWidget>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
//MainWindow w;
//w.show();
QMediaPlayer * player = new QMediaPlayer;
QVideoWidget * vw = new QVideoWidget;
player->setVideoOutput(vw);
player->setMedia(QUrl("http://21.179.127.116/Katy%20Perry%20-%20Roar%20(Official).mp4"));
vw->setGeometry(100,100,300,400);
vw->show();
player->play();
qDebug()<<player->state();
return a.exec();
}
I am using Qt Creator 3.5.1 (enterprise)

QWebEngineView RAM problems (all memory is taken by it in a minute)

Hello so i have a BIG problem with QWebViewEngine so far. Because all i did was created a QWebEngineView and said .load(QUrl("http://google.com")) and then .showFullScreen(). On start the application took about 130MB of RAM. When i pressed feel lucky on google and the page loaded suddenly the RAM started to climbing by 200mb each second and it stopped when there was no more free RAM.
Anyone had this problem, or experience with QWebEngineView.
I know its Chormium, but it seems to me as if it wasnt working correctly.
Any suggestions how to correct this?
Edited 14/08/2015 14:12
here is the code(note that most of it is commented):
#include "mainwindow.h"
#include <QtWebEngineWidgets/QtWebEngineWidgets>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QScopedPointer>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
view = new QWebEngineView();
manager = new QNetworkAccessManager();
settings = new QSettings(":/settings.ini",QSettings::IniFormat);
// connect(view,SIGNAL(loadFinished(bool)),this,SLOT(CheckPage()));
// connect(manager,SIGNAL(finished(QNetworkReply*)),this,SLOT(connection(QNetworkReply*)));
// errorOpen=false;
settings->beginGroup("URL");
myUrl = settings->value("curUrl").toString();
settings->endGroup();
// view->load(myUrl);
view->load(QUrl("http://google.com"));
view->showFullScreen();
settings->deleteLater();
}
MainWindow::~MainWindow()
{
// delete view;
// delete manager;
}
I can't reproduce under qt5-mac #5.4.2_1 from macports on OS X 10.9:
//main.cpp
#include <QtWebEngineWidgets>
#include <QApplication>
int main(int argc, char ** argv)
{
QApplication a(argc, argv);
QWebEngineView view;
view.load(QUrl("http://google.com"));
view.showFullScreen();
return a.exec();
}
# chromium-32008560.pro
QT += webenginewidgets
TARGET = chromium-32008560
TEMPLATE = app
SOURCES += main.cpp

use QCamera in Qt console application

I want to use the camera in a headless (console) qt application (at least for unit testing).
But I facing a problem with Qt. As soon I use my code in a console application, the camera won't work - the readyForCaptureChanged event of QCameraImageCapture will not be called.
If I use exactly the same code in a gui application, the event gets triggered and I can capture images.
The common code I use is that:
camera = new QCamera(cameras.at(config->cameraNumber()));
imageCapture = new QCameraImageCapture(camera);
connect(imageCapture, SIGNAL(readyForCaptureChanged(bool)), this, SLOT(readyForCapture(bool)));
camera->start(); // to start the viewfinder
// ——
void ImageCapture::readyForCapture(bool b) {
qDebug() << "ready for capture "<<b;
}
when I call this code in the gui application directly in the constructor of my MainWindow, it works (event will be triggered).
When I call this code in my qt console application, it does not work (event will not be triggered).
Can anybody help me? Thanks
** UPDATE 29. August - full code **
Console Application:
main.cpp
#include <QCoreApplication>
#include <QTest>
#include <QTimer>
#include <QDebug>
#include <runoneventloop.h>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
RunOnEventLoop * run = new RunOnEventLoop(&a);
QTimer::singleShot(0, run, SLOT(run()));
return a.exec();
}
RunOnEventLoop.cpp
#include "runoneventloop.h"
RunOnEventLoop::RunOnEventLoop(QObject *parent) :
QObject(parent)
{
}
void RunOnEventLoop::run() {
qDebug() << "hier run";
camera = new QCamera(0);
imageCapture = new QCameraImageCapture(camera);
connect(imageCapture, SIGNAL(readyForCaptureChanged(bool)), this, SLOT(readyForCapture(bool)));
camera->start(); // to start the viewfinder
}
void RunOnEventLoop::readyForCapture(bool b) {
qDebug() << "ready of capture "<<b;
}
RunOnEventLoop.h
#ifndef RUNONEVENTLOOP_H
#define RUNONEVENTLOOP_H
#include <QObject>
#include <QDebug>
#include <QCamera>
#include <QCameraImageCapture>
class RunOnEventLoop : public QObject
{
Q_OBJECT
public:
explicit RunOnEventLoop(QObject *parent = 0);
private:
QCamera* camera;
QCameraImageCapture* imageCapture;
signals:
public slots:
void run();
void readyForCapture(bool);
};
#endif // RUNONEVENTLOOP_H
GUI Application
mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
qDebug() << "hier";
camera = new QCamera(0);
imageCapture = new QCameraImageCapture(camera);
connect(imageCapture, SIGNAL(readyForCaptureChanged(bool)), this, SLOT(readyForCapture(bool)));
camera->start(); // to start the viewfinder
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::readyForCapture(bool b) {
qDebug() << "ready of capture "<<b;
}
again, it's the same code. Console App does not call the readyForCapture method, while the gui application calls it.
you can download the archive here: DOWNLOAD
If would be nice if you could provide something more of your console-based Qt application... the code you presented, how is it called by your main code?
Anyway, just guessing, if no events are raised at all maybe it is because you are not running any event loop... are you sure that your code at some point call exec() on your QCoreApplication object? Are you sure that the owner of the object from which you call connect() is the thread of QCoreApplication?

Is it possible to implement SystemTrayIcon functionality in Qt Quick application

I am writing a QtQuick desktop application. I use both c++ (for functionality) and QML (for UI) in it.
I use QQuickView to show the interface written in QML.
I want this application to reside in System Tray when minimised.
I mean a functionality similar to this example. http://qt-project.org/doc/qt-4.8/desktop-systray.html .
I am trying to implement this feature but could not find a way to do this in my Qt Quick application.
Here is my main.cpp code:
#include <QGuiApplication>
#include <QQmlEngine>
#include <QQmlContext>
#include <QQmlFileSelector>
#include <QQuickView>
#include "myapp.h"
int main(int argc, char* argv[])
{
QGuiApplication app(argc,argv);
app.setApplicationName(QFileInfo(app.applicationFilePath()).baseName());
QDir::setCurrent(qApp->applicationDirPath());
MyApp myappObject;
QQuickView view;
view.connect(view.engine(), SIGNAL(quit()), &app, SLOT(quit()));
view.rootContext()->setContextProperty("myappObject", &myappObject);
new QQmlFileSelector(view.engine(), &view);
view.setSource(QUrl("qrc:///myapp.qml"));
view.setResizeMode(QQuickView::SizeRootObjectToView);
view.show();
return app.exec();
}
Please help by providing any hint/pointers to do this.
Thanks.
I was facing the same challenge today and ended up using the following solution within main(). Works great for me when using Qt 5.3. You should of course implement a better way to check whether the first root object is your application window object or not.
#include <QApplication>
#include <QQmlApplicationEngine>
#include <QMessageBox>
#include <QAction>
#include <QMenu>
#include <QSystemTrayIcon>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
if (!QSystemTrayIcon::isSystemTrayAvailable()) {
QMessageBox::critical(0, QObject::tr("Systray"),
QObject::tr("I couldn't detect any system tray "
"on this system."));
return 1;
}
QApplication::setQuitOnLastWindowClosed(false);
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:///main.qml")));
QObject *root = 0;
if (engine.rootObjects().size() > 0)
{
root = engine.rootObjects().at(0);
QAction *minimizeAction = new QAction(QObject::tr("Mi&nimize"), root);
root->connect(minimizeAction, SIGNAL(triggered()), root, SLOT(hide()));
QAction *maximizeAction = new QAction(QObject::tr("Ma&ximize"), root);
root->connect(maximizeAction, SIGNAL(triggered()), root, SLOT(showMaximized()));
QAction *restoreAction = new QAction(QObject::tr("&Restore"), root);
root->connect(restoreAction, SIGNAL(triggered()), root, SLOT(showNormal()));
QAction *quitAction = new QAction(QObject::tr("&Quit"), root);
root->connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
QMenu *trayIconMenu = new QMenu();
trayIconMenu->addAction(minimizeAction);
trayIconMenu->addAction(maximizeAction);
trayIconMenu->addAction(restoreAction);
trayIconMenu->addSeparator();
trayIconMenu->addAction(quitAction);
QSystemTrayIcon *trayIcon = new QSystemTrayIcon(root);
trayIcon->setContextMenu(trayIconMenu);
trayIcon->setIcon(QIcon(":/resources/DatagnanLogoColor.png"));
trayIcon->show();
}
return app.exec();
}
Copy the Windos class (window.cpp/window.h) from systray example to your project, port it to Qt5 if necessary and open both from your main file:
int main(int argc, char* argv[])
{
// ...
QQuickView view;
// ...
view.show();
Window window;
window.show();
return app.exec();
}

Resources