Please provide backtrace from the crash.
if addressWholesaleAdd is QPushButton try this code
Qt Code:
void GetData::setItemCountity() { mybut->setText("dddddddd"); }To copy to clipboard, switch view to plain text mode
But if you want to manipulate ui object of store class you should find another way
Last edited by unit; 13th March 2011 at 10:17.
Try read Qt documentation before ask stupid question.
That what I get from debugger, its look like segmentation fault.Thread 3 (Thread 2404.0x540):
#0 0x7c91eb94 in ntdll!LdrAccessResource () from E:\WINDOWS\system32\ntdll.dll
#1 0x7c91d85c in ntdll!ZwDelayExecution () from E:\WINDOWS\system32\ntdll.dll
#2 0x7c8023ed in SleepEx () from E:\WINDOWS\system32\kernel32.dll
#3 0x00000000 in ?? ()
Thread 2 (Thread 2404.0xfb8):
#0 0x7c91eb94 in ntdll!LdrAccessResource () from E:\WINDOWS\system32\ntdll.dll
#1 0x7c91e399 in ntdll!ZwReplyWaitReceivePortEx () from E:\WINDOWS\system32\ntdll.dll
#2 0x77e56703 in RPCRT4!I_RpcBindingCopy () from E:\WINDOWS\system32\rpcrt4.dll
#3 0x77e56c22 in RPCRT4!I_RpcBindingCopy () from E:\WINDOWS\system32\rpcrt4.dll
#4 0x77e56a3b in RPCRT4!I_RpcBindingCopy () from E:\WINDOWS\system32\rpcrt4.dll
#5 0x77e56c0a in RPCRT4!I_RpcBindingCopy () from E:\WINDOWS\system32\rpcrt4.dll
#6 0x7c80b50b in KERNEL32!GetModuleFileNameA () from E:\WINDOWS\system32\kernel32.dll
#7 0x00000000 in ?? ()
Thread 1 (Thread 2404.0x828):
#0 0x00d28bee in QScopedPointer<QObjectData, QScopedPointerDeleter<QObjectData> >::data (this=0x4) at ../../include/QtCore/../../src/corelib/tools/qscopedpointer.h:135
#1 0x0093da9e in qGetPtrHelper<QScopedPointer<QObjectData, QScopedPointerDeleter<QObjectData> > > (p=...) at ../../include/QtCore/../../src/corelib/global/qglobal.h:2328
#2 0x00d1ebe0 in QLineEdit::d_func (this=0x0) at ../../include/QtGui/../../src/gui/widgets/qlineedit.h:275
#3 0x0098f01f in QLineEdit::setText (this=0x0, text=...) at widgets\qlineedit.cpp:382
#4 0x00401d85 in GetData::setItemCountity (this=0x9a301f0) at getdata.cpp:12
#5 0x00401f72 in GetData::qt_metacall (this=0x9a301f0, _c=QMetaObject::InvokeMetaMethod, _id=0, _a=0x22cc68) at debug\moc_getdata.cpp:72
#6 0x6a20445c in QMetaObject::metacall (object=0x9a301f0, cl=QMetaObject::InvokeMetaMethod, idx=4, argv=0x22cc68) at kernel\qmetaobject.cpp:237
#7 0x6a214bbe in QMetaObject::activate (sender=0x9a0f6e8, m=0xe6ece0, local_signal_index=2, argv=0x22cc68) at kernel\qobject.cpp:3272
#8 0x00bc2e3c in QAbstractButton::clicked (this=0x9a0f6e8, _t1=false) at tmp\moc\debug_shared\moc_qabstractbutton.cpp:206
#9 0x0093243b in QAbstractButtonPrivate::emitClicked (this=0x9a0f718) at widgets\qabstractbutton.cpp:546
#10 0x009323b9 in QAbstractButtonPrivate::click (this=0x9a0f718) at widgets\qabstractbutton.cpp:539
#11 0x00933865 in QAbstractButton::mouseReleaseEvent (this=0x9a0f6e8, e=0x22d3cc) at widgets\qabstractbutton.cpp:1121
#12 0x006041a0 in QWidget::event (this=0x9a0f6e8, event=0x22d3cc) at kernel\qwidget.cpp:8187
#13 0x009336f0 in QAbstractButton::event (this=0x9a0f6e8, e=0x22d3cc) at widgets\qabstractbutton.cpp:1080
#14 0x009d235e in QPushButton::event (this=0x9a0f6e8, e=0x22d3cc) at widgets\qpushbutton.cpp:683
#15 0x005b9706 in QApplicationPrivate::notify_helper (this=0x3d5500, receiver=0x9a0f6e8, e=0x22d3cc) at kernel\qapplication.cpp:4396
#16 0x005b7909 in QApplication::notify (this=0x22fe98, receiver=0x9a0f6e8, e=0x22d3cc) at kernel\qapplication.cpp:3959
#17 0x6a1ff9dc in QCoreApplication::notifyInternal (this=0x22fe98, receiver=0x9a0f6e8, event=0x22d3cc) at kernel\qcoreapplication.cpp:732
#18 0x00c2d53e in QCoreApplication::sendSpontaneousEvent (receiver=0x9a0f6e8, event=0x22d3cc) at ../../include/QtCore/../../src/corelib/kernel/qcoreapplication.h:218
#19 0x005b6118 in QApplicationPrivate::sendMouseEvent (receiver=0x9a0f6e8, event=0x22d3cc, alienWidget=0x9a0f6e8, nativeWidget=0x22fb24, buttonDown=0x105941c, lastMouseReceiver=..., spontaneous=true) at kernel\qapplication.cpp:3056
#20 0x0061fc63 in QETWidget::translateMouseEvent (this=0x22fb24, msg=...) at kernel\qapplication_win.cpp:3317
#21 0x0061aaa6 in QtWndProc@16 (hwnd=0x50238, message=514, wParam=0, lParam=15663318) at kernel\qapplication_win.cpp:1657
#22 0x77d18709 in USER32!GetDC () from E:\WINDOWS\system32\user32.dll
#23 0x00000000 in ?? ()
You pass a null pointer at getdata.cpp:12#3 0x0098f01f in QLineEdit::setText (this=0x0, text=...) at widgets\qlineedit.cpp:382
#4 0x00401d85 in GetData::setItemCountity (this=0x9a301f0) at getdata.cpp:12
It seems you did not initialize the addressWholesaleAdd variable.
I add this in GetData class:
And setItemcountity slot become like this:
Now I run in some problem, and the backtrace show this:Qt Code:
void GetData::setItemCountity() { form.addressWholesaleAdd->setText("sssssssssss"); }To copy to clipboard, switch view to plain text mode
However if I change the call instance in Store class to this:Qt Code:
Thread 3 (Thread 1436.0xb24): #0 0x7c91eb94 in ntdll!LdrAccessResource () from E:\WINDOWS\system32\ntdll.dll #1 0x7c91d85c in ntdll!ZwDelayExecution () from E:\WINDOWS\system32\ntdll.dll #2 0x7c8023ed in SleepEx () from E:\WINDOWS\system32\kernel32.dll #3 0x00000000 in ?? () Thread 2 (Thread 1436.0x6a4): #0 0x7c91eb94 in ntdll!LdrAccessResource () from E:\WINDOWS\system32\ntdll.dll #1 0x7c91e399 in ntdll!ZwReplyWaitReceivePortEx () from E:\WINDOWS\system32\ntdll.dll #2 0x77e56703 in RPCRT4!I_RpcBindingCopy () from E:\WINDOWS\system32\rpcrt4.dll #3 0x77e56c22 in RPCRT4!I_RpcBindingCopy () from E:\WINDOWS\system32\rpcrt4.dll #4 0x77e56a3b in RPCRT4!I_RpcBindingCopy () from E:\WINDOWS\system32\rpcrt4.dll #5 0x77e56c0a in RPCRT4!I_RpcBindingCopy () from E:\WINDOWS\system32\rpcrt4.dll #6 0x7c80b50b in KERNEL32!GetModuleFileNameA () from E:\WINDOWS\system32\kernel32.dll #7 0x00000000 in ?? () Thread 1 (Thread 1436.0x278): #0 0x00d28bee in QScopedPointer<QObjectData, QScopedPointerDeleter<QObjectData> >::data (this=0xbaadf011) at ../../include/QtCore/../../src/corelib/tools/qscopedpointer.h:135 #1 0x0093da9e in qGetPtrHelper<QScopedPointer<QObjectData, QScopedPointerDeleter<QObjectData> > > (p=...) at ../../include/QtCore/../../src/corelib/global/qglobal.h:2328 #2 0x00d1ebe0 in QLineEdit::d_func (this=0xbaadf00d) at ../../include/QtGui/../../src/gui/widgets/qlineedit.h:275 #3 0x0098f01f in QLineEdit::setText (this=0xbaadf00d, text=...) at widgets\qlineedit.cpp:382 #4 0x00401d85 in GetData::setItemCountity (this=0x9a301f0) at getdata.cpp:12 #5 0x00401f72 in GetData::qt_metacall (this=0x9a301f0, _c=QMetaObject::InvokeMetaMethod, _id=0, _a=0x22cc68) at debug\moc_getdata.cpp:72 #6 0x6a20445c in QMetaObject::metacall (object=0x9a301f0, cl=QMetaObject::InvokeMetaMethod, idx=4, argv=0x22cc68) at kernel\qmetaobject.cpp:237 #7 0x6a214bbe in QMetaObject::activate (sender=0x9a0f6e8, m=0xe6ece0, local_signal_index=2, argv=0x22cc68) at kernel\qobject.cpp:3272 #8 0x00bc2e3c in QAbstractButton::clicked (this=0x9a0f6e8, _t1=false) at tmp\moc\debug_shared\moc_qabstractbutton.cpp:206 #9 0x0093243b in QAbstractButtonPrivate::emitClicked (this=0x9a0f718) at widgets\qabstractbutton.cpp:546 #10 0x009323b9 in QAbstractButtonPrivate::click (this=0x9a0f718) at widgets\qabstractbutton.cpp:539 #11 0x00933865 in QAbstractButton::mouseReleaseEvent (this=0x9a0f6e8, e=0x22d3cc) at widgets\qabstractbutton.cpp:1121 #12 0x006041a0 in QWidget::event (this=0x9a0f6e8, event=0x22d3cc) at kernel\qwidget.cpp:8187 #13 0x009336f0 in QAbstractButton::event (this=0x9a0f6e8, e=0x22d3cc) at widgets\qabstractbutton.cpp:1080 #14 0x009d235e in QPushButton::event (this=0x9a0f6e8, e=0x22d3cc) at widgets\qpushbutton.cpp:683 #15 0x005b9706 in QApplicationPrivate::notify_helper (this=0x3d5500, receiver=0x9a0f6e8, e=0x22d3cc) at kernel\qapplication.cpp:4396 #16 0x005b7909 in QApplication::notify (this=0x22fe98, receiver=0x9a0f6e8, e=0x22d3cc) at kernel\qapplication.cpp:3959 #17 0x6a1ff9dc in QCoreApplication::notifyInternal (this=0x22fe98, receiver=0x9a0f6e8, event=0x22d3cc) at kernel\qcoreapplication.cpp:732 #18 0x00c2d53e in QCoreApplication::sendSpontaneousEvent (receiver=0x9a0f6e8, event=0x22d3cc) at ../../include/QtCore/../../src/corelib/kernel/qcoreapplication.h:218 #19 0x005b6118 in QApplicationPrivate::sendMouseEvent (receiver=0x9a0f6e8, event=0x22d3cc, alienWidget=0x9a0f6e8, nativeWidget=0x22fb24, buttonDown=0x105941c, lastMouseReceiver=..., spontaneous=true) at kernel\qapplication.cpp:3056 #20 0x0061fc63 in QETWidget::translateMouseEvent (this=0x22fb24, msg=...) at kernel\qapplication_win.cpp:3317 #21 0x0061aaa6 in QtWndProc@16 (hwnd=0x40566, message=514, wParam=0, lParam=16384221) at kernel\qapplication_win.cpp:1657 #22 0x77d18709 in USER32!GetDC () from E:\WINDOWS\system32\user32.dll #23 0x00000000 in ?? ()To copy to clipboard, switch view to plain text mode
My program doesn't crash but setItemCountity slot doesn't take its effect too!Qt Code:
GetData dd; connect(ui.addWholesaleAdd, SIGNAL(clicked()), &dd, SLOT(setItemCountity()));To copy to clipboard, switch view to plain text mode
Why you don't use pointer to object? Look my code more attentively.
In first code you try use pointer to object that does not exist.
Now you create new object, not object that use store.
You should learn c++ basics, IMHO
Try read Qt documentation before ask stupid question.
I am totally with you, I was PHP, C programmer.You should learn c++ basics, IMHO
I thought I don't need it in other classes as they will have only slots to deal with database.Why aren't you calling setupUi() anywhere?
Now I get this error after your suggestions Mr unit:
In file included from ..\Store\/getdata.h:7,
from ..\Store\getdata.cpp:3:
..\Store\/store.h:17: error: ISO C++ forbids declaration of 'GetData' with no type
..\Store\/store.h:17: error: expected ';' before '*' token
..\Store\getdata.cpp: In constructor 'GetData::GetData(Ui::Store*)':
..\Store\getdata.cpp:7: error: 'ui' was not declared in this scopeQt Code:
#ifndef STORE_H #define STORE_H #include <QMainWindow> #include "ui_store.h" #include "getdata.h" { Q_OBJECT public: private: Ui::Store ui; GetData* dd; private slots: }; #endif // STORE_HTo copy to clipboard, switch view to plain text mode
Show getdata.h and getdata.cpp
Try read Qt documentation before ask stupid question.
Qt Code:
#ifndef GETDATA_H #define GETDATA_H #include <QObject> #include "store.h" class QString; { Q_OBJECT public: GetData(Ui::Store *); private: Ui::Store form; private slots: void setItemCountity(); }; #endif // GETDATA_HTo copy to clipboard, switch view to plain text mode
Qt Code:
#include <QString> #include <QLineEdit> #include "getdata.h" GetData::GetData(Ui::Store *mainui) { ui=mainui; } void GetData::setItemCountity() { form.addressWholesaleAdd->setText("sssssssssss"); }To copy to clipboard, switch view to plain text mode
I suggest you read about object oriented programming before you start using it. It seems your PHP skills don't include using classes too. You can't blindly pass arguments to methods just because some other class or method accepted them. Stop your copy&paste approach and start a learn&experiment approach. It is obvious you have no idea what you are doing and even if unit writes your program for you, you'll immediately come back with another similar thing. Can't you see you are both inheriting Ui::Store and having an instance of Ui::Store as a member variable? You're initializing one but using the other hence you get a crash, simple as that.
SIFE (14th March 2011)
Because I am lost now, I spent last five days reading other source codes and comments with out to figure out to fix my problem.Stop your copy&paste approach and start a learn&experiment approach.
I don't think so, at least in similar problem because my whole project base just in this question as I knowyou'll immediately come back with another similar thing., I think am trying to learn C++ OOP with Qt.
You should known some basics of c++, such as class (object) and pointer. I'm write simple code for you and add some comment.
Try read Qt documentation before ask stupid question.
SIFE (14th March 2011)
SIFE (14th March 2011)
In your code you try call function of object but don't have pointer to it. So if you want manipulate ui of store class, you should have pointer to it at GetData class. I'm try your code in this way:
Qt Code:
{ Q_OBJECT public: GetData(Ui::Store*); private slots: void setItemCountity(); private: Ui::Store *ui; };To copy to clipboard, switch view to plain text modeQt Code:
GetData::GetData(Ui::Store *mainui) { ui=mainui; }To copy to clipboard, switch view to plain text modeQt Code:
GetData *dd = new GetData(&ui);To copy to clipboard, switch view to plain text mode
Last edited by unit; 13th March 2011 at 10:38.
Try read Qt documentation before ask stupid question.
Bookmarks