wxStatusBar question Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
n0wiq
In need of some credit
In need of some credit
Posts: 5
Joined: Thu Jul 05, 2018 8:59 pm

wxStatusBar question

Post by n0wiq »

I copied the following code out of the wxWidgets' book with some minor adjustmets:

Code: Select all

    statusBar = new wxStatusBar(this, wxID_ANY, wxST_SIZEGRIP);
    SetStatusBar(statusBar);
    int widths[] = {60, 60, -1};
    statusBar->SetFieldWidths(WXSIZEOF(widths), widths);
    wxString statusTextFirst = "Ready!";
    statusBar->SetStatusText(statusTextFirst, 0);

After some research, I had surmised that SetFieldWidths had been changed to SetStatusWidths from what was in the version of the wxWidgets book.

Code: Select all

    
    statusBar = new wxStatusBar(this, wxID_ANY, wxST_SIZEGRIP);
    SetStatusBar(statusBar);
    int widths[] = {60, 60, -1};
    statusBar->SetStatusWidths(WXSIZEOF(widths), widths);
    wxString statusTextFirst = "Ready!";
    statusBar->SetStatusText(statusTextFirst, 0);

I am getting a run time error somewhere. The code compiles like the two functions were the same. This is on linux/GTk version. I do not know what I did wrong or the reason for the runtime error, which does not seem to be in my code. I am just setting things up in the code so I can modify them or change them at a later date. We are still in initial stages of setting up the application. I cannot find the version of wxWidgets in "Cross Platform GUI programming with wxWidgets" but I am assuming its 2.8.x which is widely used. The version of I am using is 3.1+ with dynamic libraries. I do not know if I found a bug or something else.
User avatar
doublemax
Moderator
Moderator
Posts: 19160
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxStatusBar question

Post by doublemax »

The wxWidgets book is from 2006 and while it may still be useful to understand the basic concepts of wxWidgets, i wouldn't trust the code snippets too much. Use the samples that come with wxWidgets instead.

I can't see any obvious error in the code, are you sure the crash is related to the statusbar?
Use the source, Luke!
n0wiq
In need of some credit
In need of some credit
Posts: 5
Joined: Thu Jul 05, 2018 8:59 pm

Re: wxStatusBar question

Post by n0wiq »

The code compiles and when it crashed it stopped on the SetStatusWidths function, in the constructor of the main window, according to the call stack on one of the Fedora variants. The like the idea that the array was invalid pointer. I cannot find documentation that states the two functions are exactly the same, which is bugging me. I have not been following wxWidgets that closely for version changes of deprecated or renamed functions. I am trying to help my father build an application on Linux. I have not taken the code home and do something on Windows or another linux variant. I only find one Status bar example, which is creates a new status bar class inherited from wxStatusBar and not using the stock one like the book has, but that should not make any difference.

At this point of the program I am setting up concepts that we can later change in program design as the evolution of the application is his design and I know the direction my father taking it. I am only trying to help him out and not code it for him. I have programmed in wxWidgets before with this exact code concept but it has been a few years since I attempted an application like my father wants. It is the difference between version 2.8.x and 3.1+. If it is a renamed function, then the code behind original class giving me problems. Like you said the two code snippets have no issues and compile. It is the run time side that is giving me issues.
User avatar
doublemax
Moderator
Moderator
Posts: 19160
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxStatusBar question

Post by doublemax »

I checked wxWidgets 2.8.12, 2.6.3 and 2.5.1 and couldn't find a method called SetFieldWidths() anywhere. This must be an error in the book.

But i finally tried the code myself. SetStatusWidth() expects that the number of fields is already defined.
Use SetFieldsCount() instead and the code should work.
Use the source, Luke!
n0wiq
In need of some credit
In need of some credit
Posts: 5
Joined: Thu Jul 05, 2018 8:59 pm

Re: wxStatusBar question

Post by n0wiq »

When trying to compile the version I had out from the book, the first code block, the compiler spit back that SetFieldWidths did not exist as a member of wxStatusbar in 3.1+ we are using. This is why I found the SetStatusWidths and it compiled but gave the run time error with dynamically linked libraries. You are not seeming to understand this concept. I am not sure what the error I am looking for is so I was looking for the two different functions for definitions thinking they were defined differently or I found an error in the libraries. Something similar to a stack alignment issue I was having in assembly code programming on another program on linux. We are passing a pointer around of static data.
User avatar
doublemax
Moderator
Moderator
Posts: 19160
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxStatusBar question

Post by doublemax »

If you were running a debug build, you would have seen that this is not a "normal" crash. It's an assert telling you that the number of fields is not set.

Just use SetFieldsCount instead of SetStatusWidths and the code should work.

Code: Select all

//statusBar->SetStatusWidths(WXSIZEOF(widths), widths);
statusBar->SetFieldsCount(WXSIZEOF(widths), widths);
Use the source, Luke!
Post Reply