"No matching function for call to 'ListBox'"

#1

Hi, All.

“No matching function for call to ‘ListBox’”.

I met this error when run this ImGui code.

// ofApp.h
vector<std::string> scores;
		int indexScore;

// ofApp.cpp setup()
for (int i = 0; i < 100; i++) {
	scores.emplace_back("Score - " + ofToString(i));
}

// draw()
    ImGui::Begin("Scores");
	ImGui::ListBox("##scores", &indexScore, scores); // ## no label
	ImGui::End();

What’s wrong to me ??

Thanks.

#2

??

Thanks in advance.
Best,

#3

you can check the /openFrameworks/addons/ofxImGui/example-demo/ example:

void ofApp::draw(){
    
//required to call this at beginning
gui.begin();

if(!fileNames.empty())
    {
        
        //ofxImGui::VectorListBox allows for the use of a vector<string> as a data source
        static int currentListBoxIndex = 0;
        if(ofxImGui::VectorListBox("VectorListBox", &currentListBoxIndex, fileNames))
        {
            ofLog() << " VectorListBox FILE PATH: "  << files[currentListBoxIndex].getAbsolutePath();
        }
        
        //ofxImGui::VectorCombo allows for the use of a vector<string> as a data source
        static int currentFileIndex = 0;
        if(ofxImGui::VectorCombo("VectorCombo", &currentFileIndex, fileNames))
        {
            ofLog() << "VectorCombo FILE PATH: "  << files[currentFileIndex].getAbsolutePath();
        }
    }

//required to call this at end
gui.end();

}

is not always the same ImGui:: than ofxImGui::, check the examples carefully.

You can compile the example and check the ImGui demo. Look to ShowDemoWindow method definition while running the example to check how it looks to copy paste from it to your project:
in ofApp: … ImGui::ShowDemoWindow(&show_test_window);
–> /openFrameworks/addons/ofxImGui/libs/imgui/src/imgui_demo.cpp

1 Like
#4

PS:
if you don’t use the ofxImGui helper, and you require ImGui directly, sometimes I had to use char arrays instead of string vectors to avoid errors:
This is an example to get text from an text input string.
In this below code you can see how to convert from string to char array and backwards.

string textInput_temp = PRESET_name;

        // load char array tab2 from textInput_temp string
        char tab2[32];
        strncpy(tab2, textInput_temp.c_str(), sizeof(tab2));
        tab2[sizeof(tab2) - 1] = 0;
        // loaded string into char array

        if (ImGui::InputText("", tab2, IM_ARRAYSIZE(tab2))) {
            cout << "InputText:" << ofToString(tab2) << endl;

            // put the user typed char array to the string
            textInput_temp = ofToString(tab2);
            cout << "textInput_temp:" << textInput_temp << endl;
        }
1 Like