好日子所有QT顯示內存值
我與指針和引用熟悉自己,
道歉,如果這個問題,則爲比需要更多的信息,但它可能是幫助他人
目的:
我傳遞的test_string
內存地址爲&test_string
一個構造函數,構造函數定義接受的內存添加使用QString *ptr_test
作爲參數,並在新類中將其指定給由QString *pointer = ptr_test
定義的指針位置。
這實質上是一個傳遞引用方法,但只是一直使用內存地址。
問題:
現在我在pointer
存儲器地址,我可以使用什麼方法在地址顯示值和/或分配給這例如QString pointerValue
其中pointerValue將包含在pointer
指定的信息的所述存儲器地址的值:
長途區號
QString test_string = "This string is created in loginwindow and pointer sent to dialog";
qDebug() << "Displaying orignial variable";
qDebug() << "Displaying test_string = " << test_string;
qDebug() << "Displaying &test_string = " << &test_string;
qDebug() << "/nDisplaying tests:";
...
//code inbetween
...
LoginStatusDialog *dlgConnectStatus = new LoginStatusDialog(test_string, test_string, test_string, &test_string);
dlgConnectStatus->exec();
部首
public:
LoginStatusDialog(const QString &_login, const QString _key, const QString _auth_tok, QString *ptr_test, QWidget *parent = 0);
~LoginStatusDialog();
private:
Ui::LoginStatusDialog *ui;
QString login, key, auth_tok, *pointer;
實施
LoginStatusDialog::LoginStatusDialog(const QString &_login, const QString _key, const QString _auth_tok, QString *ptr_test, QWidget *parent) :
QDialog(parent), ui(new Ui::LoginStatusDialog), login(_login), key(_key), auth_tok(_auth_tok), pointer(ptr_test)
{
qDebug() << "Passed with const &_login";
qDebug() << "Displaying login = " << login;
qDebug() << "Displaying _login = " << _login;
qDebug() << "Displaying &login = " << &login;
qDebug() << "Displaying &_login = " << &_login;
qDebug() << "\nPassed with const _auth_tok";
qDebug() << "Displaying auth_tok = " << auth_tok;
qDebug() << "Displaying _auth_tok = " << _auth_tok;
qDebug() << "Displaying &auth_tok = " << &auth_tok;
qDebug() << "Displaying &_auth_tok = " << &_auth_tok;
qDebug() << "\nPassed address with const _key";
qDebug() << "Displaying key = " << key;
qDebug() << "Displaying _key = " << _key;
qDebug() << "Displaying &key = " << &key;
qDebug() << "Displaying &_key = " << &_key;
qDebug() << "\nPassed with *ptr_test";
qDebug() << "Displaying test = " << pointer;
qDebug() << "Displaying ptr_test = " << ptr_test;
qDebug() << "Displaying &test = " << &pointer;
qDebug() << "Displaying &ptr_test = " << &ptr_test;
QString *pointerValue = ptr_test;
qDebug() << "Display &pointerValue = ptr_test : " << pointerValue;
輸出
Displaying orignial variable
Displaying test_string = "This string is created in loginwindow and pointer sent to dialog"
Displaying &test_string = 0x7fffffffd330
Displaying tests:
Passed with const &_string_
Displaying login = "This string is created in loginwindow and pointer sent to dialog"
Displaying _login = "This string is created in loginwindow and pointer sent to dialog"
Displaying &login = 0x5555559a4550
Displaying &_login = 0x7fffffffd330
Passed with const _string_
Displaying auth_tok = "This string is created in loginwindow and pointer sent to dialog"
Displaying _auth_tok = "This string is created in loginwindow and pointer sent to dialog"
Displaying &auth_tok = 0x5555559a4560
Displaying &_auth_tok = 0x7fffffffd4c0
Passed address with const _string_
Displaying key = "This string is created in loginwindow and pointer sent to dialog"
Displaying _key = "This string is created in loginwindow and pointer sent to dialog"
Displaying &key = 0x5555559a4558
Displaying &_key = 0x7fffffffd4b0
Passed with *ptr_string_
Displaying test = 0x7fffffffd330
Displaying ptr_test = 0x7fffffffd330
Displaying &test = 0x5555559a4568
Displaying &ptr_test = 0x7fffffffcf98
Display &pointerValue = ptr_test : 0x7fffffffd330
你有什麼期望的價值是什麼?指針地址可能是一些「神祕」的東西,它們會記住對象。 – Hayt
但是,在這裏你有一些關於指針的詳細信息以及如何使用它們:http://stackoverflow.com/questions/4955198/what-does-dereferencing-a-pointer-mean – Hayt
'QString'本身不包含值。所以目前還不清楚你想做什麼。 'QString'使用裏面的'QSharedData'來保留文本。它實現了COW,所以保持原始指向內部文本是不安全的。 –