# Revision history [back]

If you take a look at the most recent documentation you can see that you can supply a user defined pointer to an object, defined as a void pointer.

If it handles a single value, you can pass that around using its pointer. If you want to pass multiple data, then you will need to construct a struct and pass all the data with a pointer to the struct. An example is below:

int ref = 1;
createTrackbar("Name","Window",0, 1, myFunc, &ref);

void myFunc(int value, void *userdata)
{
// Retrieve the data
// Needs explicit type declaration
int val = *((int*)&userdata);
}


If you take a look at the most recent documentation you can see that you can supply a user defined pointer to an object, defined as a void pointer.

If it handles a single value, you can pass that around using its pointer. If you want to pass multiple data, then you will need to construct a struct and pass all the data with a pointer to the struct. An example is below:

int ref = 1;
createTrackbar("Name","Window",0, 1, myFunc, &ref);

void myFunc(int value, void *userdata)
{
// Retrieve the data
// Needs explicit type declaration
int val = *((int*)&userdata);
}


And more general you can do it as below

cv:createTrackbar("Label", "Window" &variable, MAX_VAL, &MyClass::func, this);

void MyClass:func(int newValue, void * object) {
MyClass* myClass = (MyClass*) object;
// ...do stuff.
}


If you take a look at the most recent documentation you can see that you can supply a user defined pointer to an object, defined as a void pointer.

If it handles a single value, you can pass that around using its pointer. If you want to pass multiple data, then you will need to construct a struct and pass all the data with a pointer to the struct. An example is below:

int ref = 1;
createTrackbar("Name","Window",0, 1, myFunc, &ref);

void myFunc(int value, void *userdata)
{
// Retrieve the data
// Needs explicit type declaration
int val = *((int*)&userdata);
}


And more general you can do it as below

cv:createTrackbar("Label", "Window" &variable, MAX_VAL, &MyClass::func, this);

void MyClass:func(int newValue, void * object) {
MyClass* myClass = (MyClass*) object;
// ...do stuff.
}


To add multiple variables you will need to create a struct and provide a pointer to that

struct myData{
int variable1 = 0;
int variable2 = 0;
}

void myFunc(int value, void *userdata)
{
// Retrieve the data
// Needs explicit type declaration
myData pushed_data = *((myData*)&userdata);
}

myData test;
test.variable1 = 5;
test.variable2 = 17;

createTrackbar("Name","Window",0, 1, myFunc, &test);


If you take a look at the most recent documentation you can see that you can supply a user defined pointer to an object, defined as a void pointer.

If it handles a single value, you can pass that around using its pointer. If you want to pass multiple data, then you will need to construct a struct and pass all the data with a pointer to the struct. An example is below:

int ref = 1;
createTrackbar("Name","Window",0, 1, myFunc, &ref);

void myFunc(int value, void *userdata)
{
// Retrieve the data
// Needs explicit type declaration
int val = *((int*)&userdata);
}


And more general you can do it as below

cv:createTrackbar("Label", "Window" &variable, MAX_VAL, &MyClass::func, this);

static void MyClass:func(int newValue, void * object) {
MyClass* myClass = (MyClass*) object;
// ...do stuff.
}


To add multiple variables you will need to create a struct and provide a pointer to that

struct myData{
int variable1 = 0;
int variable2 = 0;
}

void myFunc(int value, void *userdata)
{
// Retrieve the data
// Needs explicit type declaration
myData pushed_data = *((myData*)&userdata);
}

myData test;
test.variable1 = 5;
test.variable2 = 17;

createTrackbar("Name","Window",0, 1, myFunc, &test);
{"ft_lang_label":"__label__en","ft_lang_prob":0.6954852,"math_prob":0.9789588,"size":3902,"snap":"2021-31-2021-39","text_gpt3_token_len":1023,"char_repetition_ratio":0.11775269,"word_repetition_ratio":0.94227767,"special_character_ratio":0.2831881,"punctuation_ratio":0.18829517,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9707582,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-09-17T05:21:37Z\",\"WARC-Record-ID\":\"<urn:uuid:9bf2024f-7751-494f-a17f-58669a07a3c8>\",\"Content-Length\":\"23603\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:caecc0b5-a73d-49ca-bb99-c067f7485e97>\",\"WARC-Concurrent-To\":\"<urn:uuid:c8195b6e-fe5a-433c-8542-57d956144c45>\",\"WARC-IP-Address\":\"104.21.24.86\",\"WARC-Target-URI\":\"https://answers.opencv.org/answers/91466/revisions/\",\"WARC-Payload-Digest\":\"sha1:CCY42UT4ELHLFIRRLAL3EBJBQH23UAHG\",\"WARC-Block-Digest\":\"sha1:3RUC4WKQYRNGUO7FCMYLZUZXXRZTKSFZ\",\"WARC-Identified-Payload-Type\":\"application/xhtml+xml\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-39/CC-MAIN-2021-39_segments_1631780054023.35_warc_CC-MAIN-20210917024943-20210917054943-00375.warc.gz\"}"}