PDA

View Full Version : push button is able to recieve output only once!!!



Choti
27th January 2016, 12:42
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.

Lesiok
27th January 2016, 12:47
What do You mean "buttons are returning the error" ?

Choti
27th January 2016, 13:03
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.

Lesiok
27th January 2016, 17:26
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.

Choti
28th January 2016, 10:34
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.

anda_skoa
28th January 2016, 12:26
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,
_

Choti
29th January 2016, 10:38
void MainWindow::on_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.

Lesiok
29th January 2016, 11:01
Maybe ui->valueWidget->currentItem() returns NULL pointer. Use debugger to locate a problem.

Choti
29th January 2016, 11:32
Thank you Mr.Lesiok,


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

Lesiok
29th January 2016, 11:57
No, I think you need to find the cause of the problem and not invent its workaround.

Choti
1st February 2016, 11:55
Yes ui->valuewidget->currentItem() ; is returning null pointer....

anda_skoa
1st February 2016, 12:25
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,
_

Choti
2nd February 2016, 12:19
I could not find the solution :(

anda_skoa
2nd February 2016, 12:27
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".


if (condition) {
// code executed when the condition is true
} else {
// code executed when the condition is false
}

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.