Stuck again with transfering values from one editbox to another

Started by wmbuRn, 24 July 2013, 16:34:13

wmbuRn

I want to transfer values from Panel1 EditBox 1 to Panel2 Editbox1.

This is how i get Values from editbox [its Texus code]:

// this works, i used same thing to get values and to write them on .txt file
tgui::Panel::Ptr Group1 = gui.get("Group1");
EditBoxNames[i] = Group1->get("Ime" + tgui::to_string(i)); // get EditboxNames
Group1Names.push_back(EditBoxNames[i]->getText());        // getText from editboxes
// but i cant transfer those values into another panel

tgui::Panel::Ptr Group1Napomene = gui.get("Group1Napomene");  // get Group1Napomene
                                                                                                            // which is another panel

Ime1napomene->setText(Group1Names));

The problem is Ime1napomene have error: base operand of '->' has non-pointer type 'sf::String' . I just need help with code, becouse i never learned std::vectors, and now i am asking for help. Need to finnish this fast so i can start learning things i missed.

Thank you in advance
wmbuRn




texus

Is Ime1napomene supposed to be an edit box or just some text?
Right now it is an sf::String, which doesn't has the setText function.

If it is supposed to be a string like it is now, then the line should be
Ime1napomene = Group1Names;

wmbuRn

It was sf::String. It should be: std::vector<tgui::EditBox::Ptr> Ime1napomene; So i changed it.

This is new error:  base operand of '->' has non-pointer type 'std::vector<tgui::SharedWidgetPtr<tgui::EditBox> >'

So i believe i havent used: Ime1napomene = Group1Napomene->get("Ime" + tgui::to_string(i));
// to get EditBoxes named "Ime" from Group1Napomene. Even if i add that i have same error i posted above.


texus

Is that code inside a for loop?
I think this is what you are trying to do:
Ime1napomene[i]->setText(Group1Names[i]);

wmbuRn

It compiles but i get Core dumped.

DBG said this line is error: Ime1napomene[i]->setText(Group1Names[i]);

for (unsigned i = 0; i < 30; ++i)
    {
    tgui::Panel::Ptr Group1 = gui.get("Group1");
    EditBoxNames[i] = Group1->get("Ime" + tgui::to_string(i));
    Group1Names.push_back(EditBoxNames[i]->getText());

    tgui::Panel::Ptr Group1Napomene = gui.get("Group1Napomene");
    Ime1napomene[i]->setText(Group1Names[i]);
    }


EDIT:
This is how i take values from 1 editBox and transfer that values to another EditBox:

tgui::Panel::Ptr Group1 = gui.get("Group1"); // open Group1
    tgui::EditBox::Ptr Ime1 = Group1->get("Ime1");   // open EditBox named Ime
    sf::String Ime = Ime1->getText();    // getText from editBox named Ime

    tgui::Panel::Ptr Group1Napomene = gui.get("Group1Napomene");    // open Group1Napomene
    tgui::EditBox::Ptr Ime1napomene = Group1Napomene->get("Ime1"); // Get EditBox Ime
    Ime1napomene->setText(Ime);    // Save value from EdidBox Ime from Group1 into
           // EditBox named Ime from Group1Napomene

I want to do that with vectors becouse i have a lot of EditBoxes[/code]

texus

Did you add anything to Ime1napomene earlier (with the push_back function)? What is supposed to be in there?

wmbuRn

I did nothing with Ime1napomene. Its fresh variable for purpose of using it for transfering values betwean EditBoxes. Didnt use push.back() function. And even with that function i still get same core dumped.

In Ime1napomene should be EditBoxes named "Ime" + tgui::to_string(i)
So i can use
Ime1napomene.setText();

But obviusly i am failing at making it to work :)

texus

The edit in your previous post actually made it more clear to me what you are trying to achieve.

So this should be what you want:
tgui::Panel::Ptr Group1 = gui.get("Group1");
tgui::Panel::Ptr Group1Napomene = gui.get("Group1Napomene");

for (unsigned i = 0; i < 30; ++i)
{
    tgui::EditBox::Ptr Ime1 = Group1->get("Ime" + tgui::to_string(i));
    sf::String text = Ime1->getText();

    tgui::EditBox::Ptr Ime1napomene = Group1Napomene->get("Ime" + tgui::to_string(i));
    Ime1napomene->setText(text);
}

wmbuRn

Error: /usr/local/include/TGUI/SharedWidgetPtr.hpp:271: T* tgui::SharedWidgetPtr<T>::operator->() const [with T = tgui::EditBox]: Assertion `m_WidgetPtr != __null' failed.


DBG shows line: Ime1napomene->setText(text);


Code in that EDIT is working.But it is for only 1 Editbox. I need to transfer values from 30 editboxes [with vectors] to 30 diferent EditBoxes

psuedo code:
Group1.EditBox-Ime[0] send value to > Group1Napomene.EditBox-Ime[0]
Group1.EditBox-Ime[1] send value to > Group1Napomene.EditBox-Ime[1]
...
Group1.EditBox-Ime[30] send value to > Group1Napomene.EditBox-Ime[30]
/pseudo code

This is how i took values from Group1:

for (unsigned int i = 0; i < 30; ++i)
            {
tgui::Panel::Ptr Group1 = gui.get("Group1");
EditBoxNames[i] = Group1->get("Ime" + tgui::to_string(i));
Group1Names.push_back(EditBoxNames[i]->getText());
           }

And i am missing part of how to use Ime1napomene.setText(Group1Names).

texus

Group1Napomene exists, because otherwise it should give that error somewhere else, but does it have those edit boxes inside? Because this error indicates that it can't find the requested edit box in Group1Napomene.

texus

Could you show me the code where you are creating edit boxes in Group1Napomene?

Perhaps you should just upload the whole code, so that I can look for the mistake myself.

The problem probably isn't in the lines that I posted, it lies somewhere else.
A possible problem would be that you let the edit box numbers count from 1 somewhere while in this part of code it starts from 0.

wmbuRn

Remember when you told me "Not to use for (unsigned i =1; i <= 30; ++i) ?
Well thats the problem. My Group1 EditBox Ime is (unsigned i =0; i < 30; ++i)
and Group1Napomene EditBox Ime is (unsigned i =1; i <= 30; ++i). That causes the problem. I just fixed it. Your code is working. Thank you.

Now i have to deal with "Why program takes 34-40% CPU when i click to open Group1, and it was using 4% when on main screen and loginScreen.

wmbuRn

Yup, i was uploading code to pastebin and i noticed that mistake. Thank you for your help. I can upload entire project if you want to laught at my code :)

texus

QuoteNow i have to deal with "Why program takes 34-40% CPU when i click to open Group1, and it was using 4% when on main screen and loginScreen.
Does your code sleep anywhere?

You should use sf::sleep in your main loop to just sleep like 1 millisecond.

If you don't do this then your code could even take 100% of one processor. Why it would suddenly increase I don't know, but if you don't let the program rest for a moment then such things could happen.

If you already use sleep then it is indeed an issue (one that I can't explain).

QuoteI can upload entire project if you want to
Not needed. I won't spend my time looking at someone elses code unless I have a reason for it.

wmbuRn


sf::Event event;
        while (screen.pollEvent(event))
        {

            if (event.type == sf::Event::Closed)
            {
                screen.close();
            }
                sf::sleep(sf::milliseconds(10));
                gui.handleEvent(event); // pass event to all widgets

        }  // end of (screen.pollEvent(event))


It randomly goes from 20%-34%-44%. I also have

sf::RenderWindow screen(sf::VideoMode(800, 600), "Titleeee");
    screen.setFramerateLimit(30);


Nevermind i will find it and will solve it. :)

And for the code i ment as a joke, i dont want somebody to do coding for me. Its not somebody job to do that for me. Anyway Thank you for your time and help :)

EDIT:
Just noticed it that  sf::sleep(sf::milliseconds(10)); was in my screen.pollEvent(). I moved it to while screen.isOpen(). Now program tooks 30% CPU nad wont rise nor fall. Which is good. Will try to reduce that. :)