Results 1 to 14 of 14

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

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

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

    Hello everyone,


    I have problem with the output on QListWidget. I am using 3 push buttons, READ, EDIT and CHANGE. In READ push button I have function for getting the values from the server, in EDIT button I using it to edit the values I receive form server. Finally after editing the values by using the CHNAGE button I am sending the vales back to server.

    Now I am problem is I am able to get the values only once, when I try to push the buttons READ and CHANGE they are returning the errors. My idea is to get the values whenever I push the READ and CHANGE buttons. I am not understanding whetherits the problem with the push button or with my functions.

    Can anyone please help me with this issue?


    Thank you.

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

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

    What do You mean "buttons are returning the error" ?

  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!!!

    I mean when I push th ebutton for the first time I able to recieve the data and when I do it again then there is no data recieving. I am getting error message from server.

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

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

    It has nothing to do with the button. Probably the first download data from the server is not completed correctly. We do not know what a server is, as it retrieves the data and so on. I think that a problem is in the procedure activated when the button is pressed.

  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!!!

    Thank Mr.Lesiok... the problem was solved ... its in the function not with the push button....

    Can you please also help me with error handling function for push button?.

    I mean when I click on READ button I get the data and the using EDIT button I should be able to edit the data. But when I click the EDIT button with out clicking the data the window is crashing down. So I wanted nmake something like when we push the EDIT button with out getting any data or without clicking on the data it should return a message saying "Pleae click on the data to edit" or "No data is available"....

    I want my window not to get closed when we click on EDIT button directly.. can you suggest some ideas how to get over this problem?


    Thank you.

  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!!!

    Sounds like the slot you have connected to the edit button tries to access something that is not initialized or not existant.
    Fix that and the problem should be gone.

    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!!!

    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.

  8. #8
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    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.

  9. #9
    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(); ??

  10. #10
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    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.

  11. #11
    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....

  12. #12
    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,
    _

  13. #13
    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

  14. #14
    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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.