I want to access the Qstring (m_IPAdd) from a Dialog Window
to Main Window
. However, I am stuck in passing a Qstring value in a setter function.
My error appears as a pop-up window when debug mode:
unhandled exception occurs at 0x66a77448 (Qt5Cored.dll) in __.exe:0xC0000005:
conflict happend when accessing the memory at 0xffffffffffffffff"
(I am using MSVC2010 with Qt5.0. )
Dialog Window:
private:
MainWindow *mainwindow;
...
mainwindow->setIPAdd(m_IPAdd); //m_IPAdd: member variable of class DialogWindow
MainWindow:
private:
QString m_ip;
...
void MainWindow::setIPAdd(const QString ip)
{
m_ip = ip ;
}
I also tried
void MainWindow::setIPAdd(const QString ip)
{
QString ipadd = ip; //ipadd: local variable which it can get the value of Qstring (in Debug mode)
m_ip = ipadd ; //here's the program crashes, m_ip can't get any value
}
I am wondering why the local variable ipadd
can get the value passed through argument ip
, but not m_ip
. I have even tried assigning
m_ip = "abc";
but the program also fails.
I have read through docs in qt web, but still don't know which part is useful to me.
Please give me any guides and advice. Thank you very much!!
As Dialog Window inherits from QWidget, it is a widget itself. So... you can just define your own Q_PROPERTY on it to represent the value you want to share, and register that property. With that it will be accesible from your mainwindow.