How can I dynamically name widget variables in gtkmm3?
![Multi tool use Multi tool use](http://sgv.ssvwv.com/sg/ssvwvcomimagb.png)
Multi tool use
I am trying to create 10 Gtk::Buttons without going
Gtk::Button *button1 = new Gtk::Button;
Gtk::Button *button2 = new Gtk::Button;
Gtk::Button *button3 = new Gtk::Button;
...
Gtk::Button *button10 = new Gtk::Button;
grid.add(*button1); grid.add(*button2); grid.add(*button3); //...
A Qt but similar question is here
I have tried the Qt example, but it has filename and I don't know it is for.
For string array (a list with "button1","button2","button3") loop will generate pointer errors here
grid.add(*button1)
^_______
What I need to happen is to generate dynamic naming for the Buttons' variables and then perform
grid.add(*button1);
grid.add(*button2);
grid.add(*button3);
...
grid.add(*button4);
c++ string widget instantiation gtkmm3
|
show 5 more comments
I am trying to create 10 Gtk::Buttons without going
Gtk::Button *button1 = new Gtk::Button;
Gtk::Button *button2 = new Gtk::Button;
Gtk::Button *button3 = new Gtk::Button;
...
Gtk::Button *button10 = new Gtk::Button;
grid.add(*button1); grid.add(*button2); grid.add(*button3); //...
A Qt but similar question is here
I have tried the Qt example, but it has filename and I don't know it is for.
For string array (a list with "button1","button2","button3") loop will generate pointer errors here
grid.add(*button1)
^_______
What I need to happen is to generate dynamic naming for the Buttons' variables and then perform
grid.add(*button1);
grid.add(*button2);
grid.add(*button3);
...
grid.add(*button4);
c++ string widget instantiation gtkmm3
I didn’t downvote, but your question looks more GTK oriented and there’s not enough context for most people to know what you’re asking. Try a minimal, complete, and verifiable example and show what you’ve tried to answer your question. Usually in the process you solve your own problem.
– Mike Lui
Dec 31 '18 at 13:05
Ok but I did put Gtkmm tag and let me add and show you what I have done as a code
– Bret Joseph
Dec 31 '18 at 13:31
I can't quite make out what the problem is or what you're asking. Could you be clearer?
– Lightness Races in Orbit
Dec 31 '18 at 15:04
1
Again, you're being too vague. "Generate" how? What is "something"? You say "between" but then name only one thing - "between" means inside of two things. And after clarifying your goal you still need to clearly explain what the problem is! So, what you wanted to happen, and what happened instead, and why you think that is.
– Lightness Races in Orbit
Dec 31 '18 at 15:11
1
I guess what you're trying to do is automatically generate code that will name your variablesaccount1
,account2
, etc. Don't do that. Use an array or vector.
– ptomato
Jan 3 at 0:15
|
show 5 more comments
I am trying to create 10 Gtk::Buttons without going
Gtk::Button *button1 = new Gtk::Button;
Gtk::Button *button2 = new Gtk::Button;
Gtk::Button *button3 = new Gtk::Button;
...
Gtk::Button *button10 = new Gtk::Button;
grid.add(*button1); grid.add(*button2); grid.add(*button3); //...
A Qt but similar question is here
I have tried the Qt example, but it has filename and I don't know it is for.
For string array (a list with "button1","button2","button3") loop will generate pointer errors here
grid.add(*button1)
^_______
What I need to happen is to generate dynamic naming for the Buttons' variables and then perform
grid.add(*button1);
grid.add(*button2);
grid.add(*button3);
...
grid.add(*button4);
c++ string widget instantiation gtkmm3
I am trying to create 10 Gtk::Buttons without going
Gtk::Button *button1 = new Gtk::Button;
Gtk::Button *button2 = new Gtk::Button;
Gtk::Button *button3 = new Gtk::Button;
...
Gtk::Button *button10 = new Gtk::Button;
grid.add(*button1); grid.add(*button2); grid.add(*button3); //...
A Qt but similar question is here
I have tried the Qt example, but it has filename and I don't know it is for.
For string array (a list with "button1","button2","button3") loop will generate pointer errors here
grid.add(*button1)
^_______
What I need to happen is to generate dynamic naming for the Buttons' variables and then perform
grid.add(*button1);
grid.add(*button2);
grid.add(*button3);
...
grid.add(*button4);
c++ string widget instantiation gtkmm3
c++ string widget instantiation gtkmm3
edited Jan 3 at 12:19
Bret Joseph
asked Dec 31 '18 at 12:10
![](https://lh6.googleusercontent.com/-Tb_TzigmAAU/AAAAAAAAAAI/AAAAAAAAAEQ/BDrXAAChLKk/photo.jpg?sz=32)
![](https://lh6.googleusercontent.com/-Tb_TzigmAAU/AAAAAAAAAAI/AAAAAAAAAEQ/BDrXAAChLKk/photo.jpg?sz=32)
Bret JosephBret Joseph
8410
8410
I didn’t downvote, but your question looks more GTK oriented and there’s not enough context for most people to know what you’re asking. Try a minimal, complete, and verifiable example and show what you’ve tried to answer your question. Usually in the process you solve your own problem.
– Mike Lui
Dec 31 '18 at 13:05
Ok but I did put Gtkmm tag and let me add and show you what I have done as a code
– Bret Joseph
Dec 31 '18 at 13:31
I can't quite make out what the problem is or what you're asking. Could you be clearer?
– Lightness Races in Orbit
Dec 31 '18 at 15:04
1
Again, you're being too vague. "Generate" how? What is "something"? You say "between" but then name only one thing - "between" means inside of two things. And after clarifying your goal you still need to clearly explain what the problem is! So, what you wanted to happen, and what happened instead, and why you think that is.
– Lightness Races in Orbit
Dec 31 '18 at 15:11
1
I guess what you're trying to do is automatically generate code that will name your variablesaccount1
,account2
, etc. Don't do that. Use an array or vector.
– ptomato
Jan 3 at 0:15
|
show 5 more comments
I didn’t downvote, but your question looks more GTK oriented and there’s not enough context for most people to know what you’re asking. Try a minimal, complete, and verifiable example and show what you’ve tried to answer your question. Usually in the process you solve your own problem.
– Mike Lui
Dec 31 '18 at 13:05
Ok but I did put Gtkmm tag and let me add and show you what I have done as a code
– Bret Joseph
Dec 31 '18 at 13:31
I can't quite make out what the problem is or what you're asking. Could you be clearer?
– Lightness Races in Orbit
Dec 31 '18 at 15:04
1
Again, you're being too vague. "Generate" how? What is "something"? You say "between" but then name only one thing - "between" means inside of two things. And after clarifying your goal you still need to clearly explain what the problem is! So, what you wanted to happen, and what happened instead, and why you think that is.
– Lightness Races in Orbit
Dec 31 '18 at 15:11
1
I guess what you're trying to do is automatically generate code that will name your variablesaccount1
,account2
, etc. Don't do that. Use an array or vector.
– ptomato
Jan 3 at 0:15
I didn’t downvote, but your question looks more GTK oriented and there’s not enough context for most people to know what you’re asking. Try a minimal, complete, and verifiable example and show what you’ve tried to answer your question. Usually in the process you solve your own problem.
– Mike Lui
Dec 31 '18 at 13:05
I didn’t downvote, but your question looks more GTK oriented and there’s not enough context for most people to know what you’re asking. Try a minimal, complete, and verifiable example and show what you’ve tried to answer your question. Usually in the process you solve your own problem.
– Mike Lui
Dec 31 '18 at 13:05
Ok but I did put Gtkmm tag and let me add and show you what I have done as a code
– Bret Joseph
Dec 31 '18 at 13:31
Ok but I did put Gtkmm tag and let me add and show you what I have done as a code
– Bret Joseph
Dec 31 '18 at 13:31
I can't quite make out what the problem is or what you're asking. Could you be clearer?
– Lightness Races in Orbit
Dec 31 '18 at 15:04
I can't quite make out what the problem is or what you're asking. Could you be clearer?
– Lightness Races in Orbit
Dec 31 '18 at 15:04
1
1
Again, you're being too vague. "Generate" how? What is "something"? You say "between" but then name only one thing - "between" means inside of two things. And after clarifying your goal you still need to clearly explain what the problem is! So, what you wanted to happen, and what happened instead, and why you think that is.
– Lightness Races in Orbit
Dec 31 '18 at 15:11
Again, you're being too vague. "Generate" how? What is "something"? You say "between" but then name only one thing - "between" means inside of two things. And after clarifying your goal you still need to clearly explain what the problem is! So, what you wanted to happen, and what happened instead, and why you think that is.
– Lightness Races in Orbit
Dec 31 '18 at 15:11
1
1
I guess what you're trying to do is automatically generate code that will name your variables
account1
, account2
, etc. Don't do that. Use an array or vector.– ptomato
Jan 3 at 0:15
I guess what you're trying to do is automatically generate code that will name your variables
account1
, account2
, etc. Don't do that. Use an array or vector.– ptomato
Jan 3 at 0:15
|
show 5 more comments
1 Answer
1
active
oldest
votes
Trying to make my question clear I ended up picking information from various people and combined it to the following
main.cpp
#include <gtkmm.h>
#include <map>
#include <string>
int main(int argc, char *argv)
{
auto app =
Gtk::Application::create(argc, argv,
"org.gtkmm.dynamic.buttons");
Gtk::Window window;Gtk::Grid grid;
window.set_default_size(600, 600);
std::string name = "button";
std::map<std::string, Gtk::Button*> all_buttons;
for (int i = 1; i <= 10; i++)
{
Gtk::Button *button = new Gtk::Button("Button " + std::to_string(i));
all_buttons[name] = button;
grid.add(*button);
}
window.add(grid);
window.show_all_children();
return app->run(window);
}
Thanks to ptomato & Peter87
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53987364%2fhow-can-i-dynamically-name-widget-variables-in-gtkmm3%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Trying to make my question clear I ended up picking information from various people and combined it to the following
main.cpp
#include <gtkmm.h>
#include <map>
#include <string>
int main(int argc, char *argv)
{
auto app =
Gtk::Application::create(argc, argv,
"org.gtkmm.dynamic.buttons");
Gtk::Window window;Gtk::Grid grid;
window.set_default_size(600, 600);
std::string name = "button";
std::map<std::string, Gtk::Button*> all_buttons;
for (int i = 1; i <= 10; i++)
{
Gtk::Button *button = new Gtk::Button("Button " + std::to_string(i));
all_buttons[name] = button;
grid.add(*button);
}
window.add(grid);
window.show_all_children();
return app->run(window);
}
Thanks to ptomato & Peter87
add a comment |
Trying to make my question clear I ended up picking information from various people and combined it to the following
main.cpp
#include <gtkmm.h>
#include <map>
#include <string>
int main(int argc, char *argv)
{
auto app =
Gtk::Application::create(argc, argv,
"org.gtkmm.dynamic.buttons");
Gtk::Window window;Gtk::Grid grid;
window.set_default_size(600, 600);
std::string name = "button";
std::map<std::string, Gtk::Button*> all_buttons;
for (int i = 1; i <= 10; i++)
{
Gtk::Button *button = new Gtk::Button("Button " + std::to_string(i));
all_buttons[name] = button;
grid.add(*button);
}
window.add(grid);
window.show_all_children();
return app->run(window);
}
Thanks to ptomato & Peter87
add a comment |
Trying to make my question clear I ended up picking information from various people and combined it to the following
main.cpp
#include <gtkmm.h>
#include <map>
#include <string>
int main(int argc, char *argv)
{
auto app =
Gtk::Application::create(argc, argv,
"org.gtkmm.dynamic.buttons");
Gtk::Window window;Gtk::Grid grid;
window.set_default_size(600, 600);
std::string name = "button";
std::map<std::string, Gtk::Button*> all_buttons;
for (int i = 1; i <= 10; i++)
{
Gtk::Button *button = new Gtk::Button("Button " + std::to_string(i));
all_buttons[name] = button;
grid.add(*button);
}
window.add(grid);
window.show_all_children();
return app->run(window);
}
Thanks to ptomato & Peter87
Trying to make my question clear I ended up picking information from various people and combined it to the following
main.cpp
#include <gtkmm.h>
#include <map>
#include <string>
int main(int argc, char *argv)
{
auto app =
Gtk::Application::create(argc, argv,
"org.gtkmm.dynamic.buttons");
Gtk::Window window;Gtk::Grid grid;
window.set_default_size(600, 600);
std::string name = "button";
std::map<std::string, Gtk::Button*> all_buttons;
for (int i = 1; i <= 10; i++)
{
Gtk::Button *button = new Gtk::Button("Button " + std::to_string(i));
all_buttons[name] = button;
grid.add(*button);
}
window.add(grid);
window.show_all_children();
return app->run(window);
}
Thanks to ptomato & Peter87
answered Jan 3 at 12:25
![](https://lh6.googleusercontent.com/-Tb_TzigmAAU/AAAAAAAAAAI/AAAAAAAAAEQ/BDrXAAChLKk/photo.jpg?sz=32)
![](https://lh6.googleusercontent.com/-Tb_TzigmAAU/AAAAAAAAAAI/AAAAAAAAAEQ/BDrXAAChLKk/photo.jpg?sz=32)
Bret JosephBret Joseph
8410
8410
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53987364%2fhow-can-i-dynamically-name-widget-variables-in-gtkmm3%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
D2b,IGZp XIYw8iBGFvMfeBxMfcXSSGFT3xnG zfljg4axEEu td,1r7 x1N8gshig4,vOBJH73wZcaYeCqFGeyuZ2W4j,i,IjG8,3
I didn’t downvote, but your question looks more GTK oriented and there’s not enough context for most people to know what you’re asking. Try a minimal, complete, and verifiable example and show what you’ve tried to answer your question. Usually in the process you solve your own problem.
– Mike Lui
Dec 31 '18 at 13:05
Ok but I did put Gtkmm tag and let me add and show you what I have done as a code
– Bret Joseph
Dec 31 '18 at 13:31
I can't quite make out what the problem is or what you're asking. Could you be clearer?
– Lightness Races in Orbit
Dec 31 '18 at 15:04
1
Again, you're being too vague. "Generate" how? What is "something"? You say "between" but then name only one thing - "between" means inside of two things. And after clarifying your goal you still need to clearly explain what the problem is! So, what you wanted to happen, and what happened instead, and why you think that is.
– Lightness Races in Orbit
Dec 31 '18 at 15:11
1
I guess what you're trying to do is automatically generate code that will name your variables
account1
,account2
, etc. Don't do that. Use an array or vector.– ptomato
Jan 3 at 0:15