Results 1 to 14 of 14

Thread: push button is able to recieve output only once!!!

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2016
    Posts
    22
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: push button is able to recieve output only once!!!

    void MainWindow:n_pushButton_2_clicked()
    {

    QListWidgetItem *item = ui->valueWidget->currentItem();
    item->setFlags(item->flags()|Qt :: ItemIsEditable);
    ui->valueWidget->editItem(item);

    }


    this is my code which I have implemented for EDIT button. In valueWidget I have the values which I am going to edit. But when I click on EDIT button directly the window is crashing down.

  2. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,540
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: push button is able to recieve output only once!!!

    Maybe ui->valueWidget->currentItem() returns NULL pointer. Use debugger to locate a problem.

  3. #3
    Join Date
    Jan 2016
    Posts
    22
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: push button is able to recieve output only once!!!

    Thank you Mr.Lesiok,


    Do you think I can use another function instead of currentItem(); ??

  4. #4
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,540
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: push button is able to recieve output only once!!!

    No, I think you need to find the cause of the problem and not invent its workaround.

  5. #5
    Join Date
    Jan 2016
    Posts
    22
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: push button is able to recieve output only once!!!

    Yes ui->valuewidget->currentItem() ; is returning null pointer....

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: push button is able to recieve output only once!!!

    Which means the cause of the problem is calling methods on a null pointer.

    If you can find a way to check the value of the pointer you could change the code to only use the pointer if it is valid.

    As a next step, it might be possible to get notified when the current item changes and apply the same check to determine a good value for the EDIT button's "enabled" property.

    Cheers,
    _

  7. #7
    Join Date
    Jan 2016
    Posts
    22
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: push button is able to recieve output only once!!!

    I could not find the solution

  8. #8
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: push button is able to recieve output only once!!!

    The language feature you are looking for is called "if".
    It allows to test a logical condition and then execute code depending on whether the expression evalutes to "true" or "false".
    Qt Code:
    1. if (condition) {
    2. // code executed when the condition is true
    3. } else {
    4. // code executed when the condition is false
    5. }
    To copy to clipboard, switch view to plain text mode 
    The "else" case is optional.

    In your case you can either check for the pointer being null and the code to execute being "return" or you can check for not being null and executing the code that uses the pointer.

    Cheers,
    _

    P.S.: I would strongly recommend to work through a tutorial on C++ basics before continuing.

Similar Threads

  1. Action using Push Button ?
    By steve.bush in forum Newbie
    Replies: 7
    Last Post: 25th February 2016, 15:36
  2. push button
    By arumita in forum Newbie
    Replies: 1
    Last Post: 3rd June 2014, 01:02
  3. Images is not being set on the push button
    By Charvi in forum Qt Programming
    Replies: 5
    Last Post: 7th July 2012, 09:28
  4. Need help to design push button
    By keyurparekh in forum Qt Programming
    Replies: 4
    Last Post: 29th March 2011, 13:39
  5. Push Button with image?
    By steve.bush in forum Newbie
    Replies: 10
    Last Post: 18th March 2011, 06:48

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.