Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7851527
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:12:21+00:00 2026-06-02T19:12:21+00:00

I’m practicing a bit with Gtk+. I’ve been abel to create a window, with

  • 0

I’m practicing a bit with Gtk+. I’ve been abel to create a window, with a working menu.
I can create test objects(basically, a square, asking the user to input the side length) and store them in a vector, but I can’t list them.

What I want is to show a scrolled window listing all of the stored objects, something like:

_Square 1-side:7_  
_Square 2-side:25_  

Until now, I could show the scrolled window with a text label, but none of the info about the stored objects.
Here’s the code that I have tried:

Gtk::Dialog dialog("Listing Squares",false,true);
dialog.set_default_size(500,30);
Gtk::Button close("Close");
close.signal_clicked().connect( sigc::mem_fun(*this,&Window::onFileListButtonClose) );
Gtk::VBox* vbox = dialog.get_vbox();

Gtk::ScrolledWindow sw;
sw.set_policy(Gtk::POLICY_AUTOMATIC,Gtk::POLICY_AUTOMATIC);

/** FETCH FROM ARRAY*/
  for(unsigned int i(0); i<vc.size();++i){
    Gtk::Label label( "Square number " + i );
    sw.add( label );
  }
sw.show_all_children();
vbox->pack_start( sw );
vbox = 0;
dialog.add_action_widget(close,1);
dialog.show_all_children();
dialog.run();

[EDIT:]

1) vc is a std::vector. It is a class attribute.

2) The piece of code for asking the user to input the length of the square and storing it in vc.

void Window::onMenuFileNew(void) { 
  Gtk::Dialog dialog("New Square",true,true);
  dialog.set_default_size(70,20);
  dialog.set_has_separator(true);
  Gtk::Button close("Close");

  entry.set_max_length(2);
  entry.set_text("");
  close.signal_clicked().connect( sigc::mem_fun(*this,&Window::onFileNewButtonClose) );
  Gtk::Label lab("Square side length:");
  Gtk::VBox* vbox = dialog.get_vbox();
  vbox->pack_start( lab );
  vbox->pack_start( entry );
  vbox = 0;
  dialog.add_action_widget(close,1);
  dialog.show_all_children();
  dialog.run();
}

void Window::onFileNewButtonClose(void) {
  int side = atoi( (entry.get_text()).c_str() );
  vc.push_back(Cuadrado( side ));
}

Any help would be appreciated. 🙂

PS: Before trying to list the squares, I created some of them!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T19:12:22+00:00Added an answer on June 2, 2026 at 7:12 pm

    According to the documentation, the add member function accepts widgets by reference. This means that the objects you pass here must exist throughout the lifetime of the container referencing them. In the for loop, they cease to exist as soon as the loop makes one iteration, if you create the labels before the loop, they cease to exist at the end of the function. You run into the equivalent of this: Returning a reference to a local or temporary variable.

    Now, this is a little bit shooting in the dark because I don’t really know Gtk and I don’t know if the widget is copied somewhere else, so that the original may be destructed, but it looks the way I described it above from a purely C++ point of view.

    Just to make sure this is the culprit, define all your labels globally to your application and see if they appear. If they do, you’ll know that you need to declare the labels in a way that they are alive (e.g. on heap) after that function/loop are over (and still can be destroyed appropriately).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I'm trying to create an if statement in PHP that prevents a single post
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
That's pretty much it. I'm using Nokogiri to scrape a web page what has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.