Re: [Interest] How can I use QPointer as an argument?
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Thanks Constantin, Bo and André, it's working now. And yes, it was not really a good question but that day I was a little bit nervous because the end of my timeline was very near already. I'm sure, you know what I mean ... Best regards Guenther On 01/13/2015 11:13 AM, Guenther Boelter wrote: Sorrry, I have a 'small' problem and my timeline is running so fast ... How can I use QPointer as an argument? A simple void myFunction( QPointer *myPointer ) { // do something } myFunction( myPointer ); returns 'error: ‘QPointer’ is not a type'. Thanks in advance and best regards Guenther - -- DavaoSOFT, the home of ERPel ERPel, das deutsche Warenwirtschaftssystem fuer LINUX http://www.davaosoft.com -BEGIN PGP SIGNATURE- Version: GnuPG v1 iQEcBAEBAgAGBQJUtiJtAAoJEG6MZewV4LQAc0UH/1lYQH2Va3i1ohkRzqOQmLjs yEUKry4JIQFxkIfpFfAWHk+1Xj9YtzZgKBn5pKNoiK7p/ZLjdFjdA3TMmUrj/ds8 LFPpUoAQFDY7dnH48+wbiiLvAwq2nZzbj9D+AdHjmJfJ54PHQFAfxJvpbHHA2tNQ r8WynKLSpkdrRRXOl9/y4EupUkIJx5jaxTs/S3NmvR6JMSATkGxVboehhaKmAuEo WYDwyLoYq7AZsNEk4W1EVngRTB7Fh+I1XxToQ7SHXZ9y4U43Qc/++kC4kJFGAAhX nSDDxprhddxwoMd+C9TFWfPgrJfqTQBg8/wHACoM6/DgVkOozU1PrrIdVkxM2vY= =A1tE -END PGP SIGNATURE- ___ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest
Re: [Interest] How can I use QPointer as an argument?
Den 13-01-2015 kl. 04:13 skrev Guenther Boelter: I have a 'small' problem and my timeline is running so fast ... How can I use QPointer as an argument? A simple void myFunction( QPointer *myPointer ) { // do something } myFunction( myPointer ); returns 'error: ‘QPointer’ is not a type'. You don't need to copy the QPointer. A QPointer is a weak pointer class. It is told by the object it holds, if it's deleted, and then switch to a null pointer. So in your case, you simply give the object it holds to your function instead. If you want to, you can create a QPointer in your function. void myFunction(QObject* o) { QPointer p(o); // do something } QPointer p(theRealObject); myFunction(p.data()); I hope this helps. Bo. -- Viking Software Qt and C++ developers for hire http://www.vikingsoft.eu ___ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest
Re: [Interest] How can I use QPointer as an argument?
Guenther Boelter schreef op 13-1-2015 om 04:13: Sorrry, I have a 'small' problem and my timeline is running so fast ... How can I use QPointer as an argument? A simple void myFunction( QPointer *myPointer ) { // do something } myFunction( myPointer ); returns 'error: ‘QPointer’ is not a type'. Thanks in advance and best regards As Constatin already stated: QPointer on its own does not exist. What I am wondering though, is why you feel the need to pass a _pointer_to_ a QPointer as an argument to myFunction? QPointer is a smart-pointer: it acts as a normal pointer, and then provides some other cleverness. In this case, the cleverness provided is that it automatically resets to 0 if the QObject you point to is deleted, so it can't become a dangling pointer. Passing a QPointer* is possible of course, but probably not what you wanted to do. Smart pointers are small enough to just copy as values. A valid use case for passing a QPointerMyClass* is if you are really passing an array of QPointers, though I'd probably go for another solution like a QVectorQPointerMyClass then. André ___ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest
[Interest] How can I use QPointer as an argument?
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Sorrry, I have a 'small' problem and my timeline is running so fast ... How can I use QPointer as an argument? A simple void myFunction( QPointer *myPointer ) { // do something } myFunction( myPointer ); returns 'error: ‘QPointer’ is not a type'. Thanks in advance and best regards Guenther -BEGIN PGP SIGNATURE- Version: GnuPG v1 iQEcBAEBAgAGBQJUtI1BAAoJEG6MZewV4LQAnSgH/RCyMqWG3h7rXXP+OCJKFTsD OWNGSi0uvkfO3Va4RjHWSRHveZY/0SD5V7+EpUAtI/cRhdsOinjr864odObwMaHe hTMkHSSA2WX+ptwZ/L5NWaeEFFE6tKvHNhB2iCbnbm67f/xQN8K7tus5tE24qNxH q0+QOtZ8F0wgQa/Rpq0CyPcdEDnCGLiPQtdp6WKRaCtyBVL7gsO5QjIToENCY6on PtozdT0nAyrXbO90orAdghHd3jAffpsEJmv+5Y9/mjxZl/t/oLNN6U8BLHg5eOGc 5UnaeN0NYLekG/KLrfcdu+V6lROQiyw1T6ugb+SpcEV0SJRtnQUejBt05ys0vZM= =ezn6 -END PGP SIGNATURE- ___ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest
Re: [Interest] How can I use QPointer as an argument?
QPointer is a template class and therefore can't be used by itself, i.e. without specifying the template parameter. In your case you should either: 1) specify a particular QObject-related class in the declaration/definition of myFunction(), e.g. void myFunction (QPointerQWidget* myPointer) { // do something } 2) define myFunction() as a template function, e.g. template class T void myFunction (QPointerT* myPointer) { // do something } On 01/13/2015 06:13 AM, Guenther Boelter wrote: Sorrry, I have a 'small' problem and my timeline is running so fast ... How can I use QPointer as an argument? A simple void myFunction( QPointer *myPointer ) { // do something } myFunction( myPointer ); returns 'error: ‘QPointer’ is not a type'. Thanks in advance and best regards Guenther signature.asc Description: OpenPGP digital signature ___ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest