Results 1 to 10 of 10

Thread: Writing to statusBar causes bug in my application

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Writing to statusBar causes bug in my application

    int* p;
    *p; <--- bang!

    You deref an uninitialised pointer and you get a crash. Did you use your debugger yet? You haven't mentioned anything, and it should be your first point of call**. You should be looking for horses before you blame zebras...

    **
    edit: oh yes, you said you can't expand it. Didn't that seem strange to you? I wonder why it's not working? Probably because it hasn't been initialised...
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  2. #2
    Join Date
    Nov 2011
    Posts
    51
    Thanks
    11
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Writing to statusBar causes bug in my application

    Quote Originally Posted by amleto View Post
    int* p;
    *p; <--- bang!
    Ah, okay this is what you meant with un-initialized. Yes that is very likely. I thought this was what d_stranz was referring to when he mentioned memory corruption, since an un-initialized pointer easily can lead to memory corruption (I guess), and I thought you were referring to an uninitialized float (since the bug was that I got a very strange value for a float, although I didn't mention it).

    Quote Originally Posted by amleto View Post
    Did you use your debugger yet?
    No, I'm sorry I haven't had the opportunity yet, so maybe it's stupid of me to ask more questions. But I am going to do it soon and get back to this thread when I have found the reason for the bug.

    Quote Originally Posted by amleto View Post
    edit: oh yes, you said you can't expand it. Didn't that seem strange to you? I wonder why it's not working? Probably because it hasn't been initialised...
    Do you mean that the ui object hasn't been initialized? The ui object must have been initialized, since my main window constructor definition starts like this:

    Qt Code:
    1. mainwin::mainwin(QWidget *parent) :
    2. QMainWindow(parent),
    3. ui(new Ui::mainwin)
    4. {
    To copy to clipboard, switch view to plain text mode 

    and that's the constructor I use when I'm creating the mainwin object, so the ui object has been initialized with an initializer.

    I'm thinking that the ui object has been corrupted, and that I have some uninitialized pointer somewhere that I'm using, like you said. But how can I find places where I'm dereferring uninitialized pointers?

  3. #3
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Writing to statusBar causes bug in my application

    What about objects inside ui?
    Are you calling ui->setupUi(this)?

    I'm guessing you are, otherwise you wouldn't see anything, but I may be wrong.

  4. #4
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Writing to statusBar causes bug in my application

    Quote Originally Posted by Yes View Post
    But how can I find places where I'm dereferring uninitialized pointers?
    attach your debugger when your program crashes / look at the call stack when debugging and the error occurs.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

Similar Threads

  1. Writing to StatusBar
    By snowsoman in forum Qt Programming
    Replies: 1
    Last Post: 23rd November 2011, 16:50
  2. Replies: 2
    Last Post: 26th February 2011, 15:25
  3. Writing a Qt console application
    By sashoalm in forum Newbie
    Replies: 6
    Last Post: 7th February 2011, 17:42
  4. Replies: 1
    Last Post: 20th February 2010, 04:26
  5. statusbar
    By bhogasena in forum Qt Programming
    Replies: 7
    Last Post: 3rd February 2009, 14:54

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.