display pointer memory address
First post from a qt newbie.
How can I achieve this in qt4. What header
files would I need to include? If possible a simple code example would be really appreciated.
int variable = 2;
int* pointer = &variable;
cout<<*pointer<<endl; //displays 2
cout<<pointer<<endl; //displays the location of "variable"
Thanks in advance.
Milo
Re: display pointer memory address
Code:
#include <QApplication>
#include <QLabel>
int main(int argc, char** argv)
{
int variable = 2;
int* pointer = &variable;
label.setText("number="+num+"pointer="+p);
label.show();
return app.exec();
}
Re: display pointer memory address
Mr Death,
Thank you for the fast reply.
Unfortunately the build finishes with the following error.
error: call of overloaded ‘number(int*&, int)’ is ambiguous
Build complains that QString does not seem to have a candidate number() function
This is the same issue that led me to posting. I was unable to find a Qt function to solve the issue and figured I must be missing something simple.
Any ideas ??
Re: display pointer memory address
I guess its getting confused in the pointer address
try it with double conversion -
QString p=QString::number((double)pointer,16);
Re: display pointer memory address
Same casting issue it would seem.
Build Error
error: invalid cast from type ‘int*’ to type ‘double’
This should be really straight forward right?
Re: display pointer memory address
cast it to int:
Code:
String p
=QString::number((int)pointer,
16);
this works for me;
Re: display pointer memory address
i have tested it... it works for int instead of double
QString p=QString::number((int)pointer,16);
edit: i was a lil late in reply... did not saw the above post..:p:D
XX
Re: display pointer memory address
Thanks a heap for your replies and your solution faldżip of casting to (int).
Re: display pointer memory address
Still useful after all these years. Thanks.