Usage of createTrackbar for QT control panel possible?

asked 2014-07-10 07:16:35 -0500

Brixus gravatar image


I would like to use the function "createTrackbar" for creating a trackbar on the QT control panel.

The info about this feature you can find here:

If I use "cvCreateTrackbar" with NULL as window everything works fine but with createTrackbar it ist not working.

Has anybody an idea how to fix this?

This is a working minimal:

#include "opencv2/core/core.hpp"
#include <opencv2/highgui/highgui.hpp>

using namespace cv;    

const int slider_1_max  = 255;
      int slider_1 = 0;
const int slider_2_max  = 255;
      int slider_2 = 0;

Mat test;

void on_trackbar_1(int pos)

void on_trackbar_2(int pos, void*)

int main ()

     cvCreateTrackbar("One",NULL, &slider_1,slider_1_max, on_trackbar_1);

     //Not working:
     //createTrackbar("Two",NULL, &slider_2,slider_2_max, on_trackbar_2);

 while (char(waitKey(1)) != 'q'){}
 return 0;

Thank you very much :-)

edit retag flag offensive close merge delete


damn, that tutorial needs an overhaul...

berak gravatar imageberak ( 2014-07-10 07:35:42 -0500 )edit

are you on win ? usually, when you can use a cv* function, but not the cv:: equivalent, it is a linker problem(due to std::string)

berak gravatar imageberak ( 2014-07-10 09:25:08 -0500 )edit

No, I am using Ubuntu.

The error is: "terminate called after throwing an instance of 'std::logic_error' what(): basic_string::_S_construct null not valid"

If it is really a linker problem, how can I solve it? I use OpenCV a lot with the C++ functions and there are no other errors.

Brixus gravatar imageBrixus ( 2014-07-10 10:02:15 -0500 )edit