Error: cannot access member ... of deleted QObject. Need help, please!
Hi,
First of all, I'm not familiar with js and QT neither.
I'm trying to create a simple script that displays a GUI on which I could choose any owned product I want, to batch export them. Nothing difficult, but I have that error message that randomly appears very often : "cannot access member 'title' of deleted Qobject" ("title', or any other attribute I try to get)
I tried to minimize my code to locate the cause, but nothing to do : error is too random so it's really hard to locate.
For example : if I run my script for the first time since I launched Daz, Error probability is 100%! then I re-run the script: success probability is 100% !!! then I take a break, come back 5 minutes later (script's still running, but doing nothing), It doesn't work anymore because most of QObjects have been deleted by their own will!
So my question is : did I miss something? is that a common mistake that requires doing something specific to be fixed?
I can join my script if needed, thanks a lot for any help!
Comments
I just simplified my code, hope this will help you to help me^^
My problem is :
- I launch Daz.
- I execute the script and click on the button. It displays the assets liist on the left listbox. But when I click on an asset, nothing happens. I close the script.
- I relaunch the script, without any changes : It works (for about 5 minutes. Then Qobjects get deleted...).
I hope that I'm understandable... Could someone explain me what I'm doing wrong? thanks!
I checked the code and found some problems, I understand your not familiar with JS or Qt, but the will is more important than knowledge. First, some healthy code recommendations:
On line:
var contentType = oAsset.contentType.toString();
You are relying on getting a contentType value, but it is not always the case, a quick test I made returned some empty values, so, you must test against empty strings.
As it is a lengthy operation(many nested for loops) you must yield control to DS to do house keeping tasks by calling processEvents() function.
On some lines you are instancing with wDlg as parent, in other lines you are instancing with wLyt2 as parent.
I applied some validations here and there and the error disappeared.
HTH
Thanks a lot for the answer!
I will apply your recommendations. I did ckeck values before to use them, but removed that part of the code to simplify it... but you're right, on line "var contentType = ...toString()", I didn't check the value, because I supposed that even if value is undefined, toString method will work...
I didn't really understand the second part of your message as I'm not native english speaker, but I think that's exactly what I was looking for, so I'll work on it.
Thanks again!
I did what you told me and continued my script, and didn't have any other error of that kind for now two days. I think that was essentially the bad layout instancing that was fatal...
Once again, thank you !
You're welcome, I'm glad I could help.