Qt Signal mapper and sending QLabel by reference and OpenCv 2
-
Can you describe the workflow of that functionality ? e.g. User click on button, show dialog with image from source, etc… What will the user input change ?What you want to do with the timer ?
-
Okay,.. i'll explain
there is a Qmainwindow that open when i press on an action in the menu bar of the original mainwindow, there is a button says Start and a QLabel to view image - there will be a label for status bar but not implemented yet - user click the button, a timer begin to count, when it times out, the connect - i'll get straight to explaining the SLOT - will activate a method that takes a frame and draw some boxes using Opencv methods, then convert this frame to QImage and show it on the label.
click signal - > activate timer -> call slot -> query frame -> view it on a passed by reference label.
this is the first part in my project, i already finished it in Visual studio, but Qt is much more interesting, there is python and c++ ♥
i'm grateful for all the help here)))) -
Then my earlier suggestions still stand. Keep the image processing in BinaryImage and emit the QPixmap when ready. It really doesn't need know about that QLabel.
-
but how can i update the label, and if the QPixmap will be the return type of a method, how would i keep calling it in a SLOT which is void ?!
i use the timer to manage the GUI, cause i don't want things to happen fast and make the GUI not responding -
I didn't suggest to make QPixmap the return type of anything. Use a signal that looks like:
@
signals:
void newPixmapReady(const QPixmap& pixmap);
@If you don't want to lock your GUI thread, you can get some inspiration from the Mandelbrot example
-
as far as i know that "connect" only accept signal and slot with the same parameters, but there is no timeout() with QPixmap ?!
that's why i use SignalMapper and it doesn't work at all for me, i feel that i've a misunderstanding about the SignalMapper xDalso none of the connect statements that i wrote in the code have worked
-
It's more about the design. Your timer should be connected to that slot that does the processing, then from this slot emit a signal with the QPixmap
-
but still timers doesn't work in the code up there, is there some problem in they way i made them ?!
-
You should really first cleanup the code. Using a QSignalMapper for that task is just an overkill.
Anyway, one of the thing is that you are mapping the mapper to the widget which is not the way it's supposed to work. Have a look at QSignalMapper's documentation, there's an example of how it works.
-
yeah, you're right, sorry for making it too long, any technical design recommendation about things i can have a look at else the Mandelbrot example ?!
-
The documentation (Qt 5 latest version) of QThread, you'll see the various implementation possibilities. Then don't try to do everything at once. First get your image on the widget, then move that code to a worker object. Also, since you want to do it at regular interval, why not simply use a QTimer ?
Hope it helps
-
yup, thanks, i'm reading a book about QT Design Patterns, i think i should learn it in a better way
-
Good book, there are several that you can learn from