Skip to content

Cannot pass String variable into addControl argument #328

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
TheGreatPintoJ opened this issue Apr 13, 2025 · 2 comments
Open

Cannot pass String variable into addControl argument #328

TheGreatPintoJ opened this issue Apr 13, 2025 · 2 comments

Comments

@TheGreatPintoJ
Copy link

TheGreatPintoJ commented Apr 13, 2025

Describe the bug
When using ESPUI.addControl(Button, title, title, Alizarin, mainTab);
I get the error:

src/main.cpp:53:66: error: no matching function for call to 'ESPUIClass::addControl(ControlType, String&, String&, ControlColor, uint16_t&)'
ESPUI.addControl(Button, title, title, Alizarin, mainSelector);

To Reproduce
Steps to reproduce the behavior:

  1. In any working ESPUI sketch, try:
    String title = "New Option";
    ESPUI.addControl(Button, title, title, Alizarin, mainTab);
  2. Build or compile
  3. Observe error

Expected behavior
No error

Desktop (please complete the following information):

  • Windows 11
  • VSCode and PlatformIO
Full error Compiling .pio\build\seeed_xiao_esp32s3\src\main.cpp.o src/main.cpp: In function 'void addOption(Control*, int)': src/main.cpp:54:61: error: no matching function for call to 'ESPUIClass::addControl(ControlType, String&, String&, ControlColor, uint16_t&)' ESPUI.addControl(Button, title, title, Alizarin, mainTab); ^ In file included from src/main.cpp:3: .pio/libdeps/seeed_xiao_esp32s3/ESPUI/src/ESPUI.h:135:14: note: candidate: 'uint16_t ESPUIClass::addControl(ControlType, const char*)' uint16_t addControl(ControlType type, const char* label); ^~~~~~~~~~ .pio/libdeps/seeed_xiao_esp32s3/ESPUI/src/ESPUI.h:135:14: note: candidate expects 2 arguments, 5 provided .pio/libdeps/seeed_xiao_esp32s3/ESPUI/src/ESPUI.h:136:14: note: candidate: 'uint16_t ESPUIClass::addControl(ControlType, const char*, const String&)' uint16_t addControl(ControlType type, const char* label, const String& value); ^~~~~~~~~~ .pio/libdeps/seeed_xiao_esp32s3/ESPUI/src/ESPUI.h:136:14: note: candidate expects 3 arguments, 5 provided .pio/libdeps/seeed_xiao_esp32s3/ESPUI/src/ESPUI.h:137:14: note: candidate: 'uint16_t ESPUIClass::addControl(ControlType, const char*, const String&, ControlColor)' uint16_t addControl(ControlType type, const char* label, const String& value, ControlColor color); ^~~~~~~~~~ .pio/libdeps/seeed_xiao_esp32s3/ESPUI/src/ESPUI.h:137:14: note: candidate expects 4 arguments, 5 provided .pio/libdeps/seeed_xiao_esp32s3/ESPUI/src/ESPUI.h:138:14: note: candidate: 'uint16_t ESPUIClass::addControl(ControlType, const char*, const String&, ControlColor, uint16_t)' uint16_t addControl(ControlType type, const char* label, const String& value, ControlColor color, uint16_t parentControl); ^~~~~~~~~~ .pio/libdeps/seeed_xiao_esp32s3/ESPUI/src/ESPUI.h:138:14: note: no known conversion for argument 2 from 'String' to 'const char*' .pio/libdeps/seeed_xiao_esp32s3/ESPUI/src/ESPUI.h:139:14: note: candidate: 'uint16_t ESPUIClass::addControl(ControlType, const char*, const String&, ControlColor, uint16_t, std::function)' uint16_t addControl(ControlType type, const char* label, const String& value, ControlColor color, uint16_t parentControl, std::function callback); ^~~~~~~~~~ .pio/libdeps/seeed_xiao_esp32s3/ESPUI/src/ESPUI.h:139:14: note: candidate expects 6 arguments, 5 provided .pio/libdeps/seeed_xiao_esp32s3/ESPUI/src/ESPUI.h:213:14: note: candidate: 'uint16_t ESPUIClass::addControl(ControlType, const char*, const String&, ControlColor, uint16_t, std::function, void*)' uint16_t addControl(ControlType type, const char* label, const String& value, ControlColor color, uint16_t parentControl, std::function callback, void* userData) ^~~~~~~~~~ .pio/libdeps/seeed_xiao_esp32s3/ESPUI/src/ESPUI.h:213:14: note: candidate expects 7 arguments, 5 provided .pio/libdeps/seeed_xiao_esp32s3/ESPUI/src/ESPUI.h:281:14: note: candidate: 'uint16_t ESPUIClass::addControl(ControlType, const char*, const String&, ControlColor, uint16_t, Control*)' uint16_t addControl(ControlType type, const char* label, const String& value, ControlColor color, uint16_t parentControl, Control* control); ^~~~~~~~~~ .pio/libdeps/seeed_xiao_esp32s3/ESPUI/src/ESPUI.h:281:14: note: candidate expects 6 arguments, 5 provided *** [.pio\build\seeed_xiao_esp32s3\src\main.cpp.o] Error 1
(I don't know why its reformatting the error without newlines)

I should also mention I found a (hopefully temporary) workaround by using strdup(title.c_str())

@nodoubtman
Copy link

nodoubtman commented Apr 14, 2025

Hello, try to pass a char array.

char bufTitle[12];
snprintf(bufTitle,sizeof(bufTitle), "%s", "New Option");

ESPUI.addControl(Button, bufTitle, bufTitle, Alizarin, mainTab);

Let me know if it works.
Have a nice day.
Marc.

@TheGreatPintoJ
Copy link
Author

It doesn't add a button, but when I turn it to Option and add it to a selector, it adds a blank option...
thanks for the suggestion though!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants