Access IP camera from Qt
-
Can you describe the various parts of your application so we can ensure that they are not influencing each other.
By the way, there's no need to set cache each time. Just set the property where you declarer image1. That's one less thing consuming time uselessly.
-
@SGaist It's my main function:
int main(int argc, char *argv[]) { QApplication app(argc, argv); QDeclarativeView *engine = new QmlApplicationViewer(); Gps *gps = new Gps(); // Class to read Gps (serial port 0). Interval: 10000ms SerialPort *serial = new SerialPort(); // Read Serial Port (serial port 1). Interval: 300ms if(serial->getMonitor()) { qDebug() << "Starting Monitor"; Monitor *monitor = new Monitor(engine, serial); serial->setMonitor(monitor); } return app.exec(); }
The class SerialPort start the write on serial port with a forever loop. Its working well, without delays.
When the serial read the response, the response is sent to monitor Class and this class is responsable to format the digits and write on screen (QML file). Therefore, each 300 ms my QML file is updated too (with the response of serial port).
-
Then where's the camera in that setup ?
-
@SGaist The camera is loaded in a different QML, look:
import QtQuick 1.1 Rectangle { width: 300 height: 400 Image { id: camera1 objectName: "camera1" x: 39 y: 0 width: 160 height: 120 source: "http://192.168.0.110/image/jpeg.cgi" cache: false Timer { interval: 300 running: true repeat: true onTriggered: { camera1.source = "http://192.168.0.110/image/jpeg.cgi"; } } } ... }
The QML is loaded on Monitor class:
Monitor::Monitor(QDeclarativeView *engine, Monitor *m) { engine->setSource(QUrl("qrc:/views/Monitor.qml")); window = qobject_cast< QObject * >( engine->rootObject() ); engine->showFullScreen(); monitor = m; engine->rootContext()->setContextProperty("mainmonitor",this); }
-
You just need to create two Images with same position add property
visible: status == Image.ready
and on also add sth like this
onStatusChanged:{ if(status == Image.ready){ //here reload the other image image2.source = ""; image2.source = cameraSource; } }
Add the same thing in image2 but this timer reload image1
onStatusChanged:{ if(status == Image.ready){ //here reload the other image image1.source = ""; image1.source = cameraSource; } }
Also at creation just set source to cameraSource for one image and for the other leave it empty,.
Hope it helps.
-
@kolegs Thank you so much. I created this code and the performance was very better. I'm reading two IP cameras now with it.
Of course that the delay is existing (each 2 seconds the image is updated). I think that I need to improve my code. I'm using 98% of my CPU, but I need to do many routines :(
Thank you so much again
-
This post is deleted!