called pointer is null...
-
At a guess, I would bet that
textEditPtr_DEBUG
may not be a valid object. In brief:QTextEdit *textEditPtr_DEBUG = MWCCF->centralWidget()->findChild("textEdit_2");
if (textEditPtr_DEBUG) {
// textEditPtr_DEBUG is valid here
} else {
// textEditPtr_DEBUG is not valid here
// and we don't do anything to create a valid object ...
}
// At this point, if the else branch was followed, above then do not
// have a valid textEditPtr_DEBUG object ...
textEditPtr_DEBUG->append(text); //crashes as noted aboveKeep Calm and Carry On
-
Well, it's pretty obvious this call:
QTextEdit *textEditPtr_DEBUG = MWCCF->centralWidget()->findChild("textEdit_2");
didn't find and return the object you thought it did. Whatever "textEdit_2" is either doesn't exist or it's not in the container you think it is and are telling the code it's in. I know you're saying "OK here", but is it really? Put a breakpoint on the if statement right above that and run the code under the debugger. When it breaks, hover the mouse over
textEditptr_DEBUG
and see if it actually has a value that isn't a bunch of zeros and points to the actual object you think it does.Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles. Dave Kreskowiak
-
Well, it's pretty obvious this call:
QTextEdit *textEditPtr_DEBUG = MWCCF->centralWidget()->findChild("textEdit_2");
didn't find and return the object you thought it did. Whatever "textEdit_2" is either doesn't exist or it's not in the container you think it is and are telling the code it's in. I know you're saying "OK here", but is it really? Put a breakpoint on the if statement right above that and run the code under the debugger. When it breaks, hover the mouse over
textEditptr_DEBUG
and see if it actually has a value that isn't a bunch of zeros and points to the actual object you think it does.Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles. Dave Kreskowiak
WHOPS This is irrelevant - wrong function and pointer... Are you really saying that my if(textEditPtr_DEBUG) check is bogus? Here is what I have as info see the highlighted part - it sure does not look as pointer besides it is wrong value anyway... BUT why is it actually printing to CORRECT widget ? PS I am sorry to post so much irrelevant stuff.
Locals BTUL @0x555555b5dc40 BT\_Utility\_Library CommandListArrayIndex 32767 int MWCCF "MainWindow\_C\_CODE\_FORM" MainWindow\_C\_CODE\_FORM QSL <3 items> QStringList index 8 int subWindow\_TEST\_BREAK @0x5555558139e0 QMenuBar **textEditPtr "textEdit\_4" QTextEdit** \[QAbstractScrollArea\] "textEdit\_4" QAbstractScrollArea \[d\] @0x555555668f10 QTextEditPrivate \[parent\] "frame\_5" QFrame \[children\] <4 items> QList \[0\] "qt\_scrollarea\_viewport" QWidget \[1\] "qt\_scrollarea\_hcontainer" QAbstractScrollAreaScrollBarContainer \[2\] "qt\_scrollarea\_vcontainer" QAbstractScrollAreaScrollBarContainer \[3\] @0x555555691470 QTextEditControl \[properties\] \[methods\] <43 items> \[extra\] staticMetaObject @0x7ffff7c442e0 QMetaObject textEditPtr\_RUN 0x55ff00c50001 QTextEdit\* this @0x7fffffffe0a8 MainWindow\_QT\_Bluetooth Inspector Expressions "(?<=\\thci0 SetupRun 10442863786053945429 QString (MainWindow\_QT\_Bluetooth \* const, int, QString, QString, QString, QString, QString, QString) Return Value Tooltip MWCCF "MainWindow\_C\_CODE\_FORM" MainWindow\_C\_CODE\_FORM
-
WHOPS This is irrelevant - wrong function and pointer... Are you really saying that my if(textEditPtr_DEBUG) check is bogus? Here is what I have as info see the highlighted part - it sure does not look as pointer besides it is wrong value anyway... BUT why is it actually printing to CORRECT widget ? PS I am sorry to post so much irrelevant stuff.
Locals BTUL @0x555555b5dc40 BT\_Utility\_Library CommandListArrayIndex 32767 int MWCCF "MainWindow\_C\_CODE\_FORM" MainWindow\_C\_CODE\_FORM QSL <3 items> QStringList index 8 int subWindow\_TEST\_BREAK @0x5555558139e0 QMenuBar **textEditPtr "textEdit\_4" QTextEdit** \[QAbstractScrollArea\] "textEdit\_4" QAbstractScrollArea \[d\] @0x555555668f10 QTextEditPrivate \[parent\] "frame\_5" QFrame \[children\] <4 items> QList \[0\] "qt\_scrollarea\_viewport" QWidget \[1\] "qt\_scrollarea\_hcontainer" QAbstractScrollAreaScrollBarContainer \[2\] "qt\_scrollarea\_vcontainer" QAbstractScrollAreaScrollBarContainer \[3\] @0x555555691470 QTextEditControl \[properties\] \[methods\] <43 items> \[extra\] staticMetaObject @0x7ffff7c442e0 QMetaObject textEditPtr\_RUN 0x55ff00c50001 QTextEdit\* this @0x7fffffffe0a8 MainWindow\_QT\_Bluetooth Inspector Expressions "(?<=\\thci0 SetupRun 10442863786053945429 QString (MainWindow\_QT\_Bluetooth \* const, int, QString, QString, QString, QString, QString, QString) Return Value Tooltip MWCCF "MainWindow\_C\_CODE\_FORM" MainWindow\_C\_CODE\_FORM
Hell if I know. I haven't C++'d in about 15 years and I don't do Qt. The process of checking return values for exactly what you expect them to be is just universal.
Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles. Dave Kreskowiak
-
The code, and the problem, is quite clear.
QTextEdit \*textEditPtr\_DEBUG = MWCCF->centralWidget()->findChild("textEdit\_2"); if (textEditPtr\_DEBUG) { text = " Found textEdit "; OK here qDebug() << text; textEditPtr\_DEBUG->append(text); text = " DEBUG START DEBUG trace with textEdit\_2" ; qDebug() << text; textEditPtr\_DEBUG->append(text); } else { text = "Did not find any QTextEdit"; qDebug() << text; } // ?? what why ?? text = " DEBUG START DEBUG trace with textEdit\_2" ; textEditPtr\_DEBUG->append(text); crash - null pointer here ??
At line 1 you (try to) create a pointer to some object. At line 2 you test if that object is NULL, and if it is not, then you execute lines 4 to 10 If the object is NULL, then you skip to line 14 But then at line 19 you try to use a pointer which you may already have determined is NULL. Unfortunately the debug output you have shown above does not match that code, so I am making some assumptions here. [edit] Also it does not help you to have the same debug message in two different places. [/edit]
-
The code, and the problem, is quite clear.
QTextEdit \*textEditPtr\_DEBUG = MWCCF->centralWidget()->findChild("textEdit\_2"); if (textEditPtr\_DEBUG) { text = " Found textEdit "; OK here qDebug() << text; textEditPtr\_DEBUG->append(text); text = " DEBUG START DEBUG trace with textEdit\_2" ; qDebug() << text; textEditPtr\_DEBUG->append(text); } else { text = "Did not find any QTextEdit"; qDebug() << text; } // ?? what why ?? text = " DEBUG START DEBUG trace with textEdit\_2" ; textEditPtr\_DEBUG->append(text); crash - null pointer here ??
At line 1 you (try to) create a pointer to some object. At line 2 you test if that object is NULL, and if it is not, then you execute lines 4 to 10 If the object is NULL, then you skip to line 14 But then at line 19 you try to use a pointer which you may already have determined is NULL. Unfortunately the debug output you have shown above does not match that code, so I am making some assumptions here. [edit] Also it does not help you to have the same debug message in two different places. [/edit]
-
The code, and the problem, is quite clear.
QTextEdit \*textEditPtr\_DEBUG = MWCCF->centralWidget()->findChild("textEdit\_2"); if (textEditPtr\_DEBUG) { text = " Found textEdit "; OK here qDebug() << text; textEditPtr\_DEBUG->append(text); text = " DEBUG START DEBUG trace with textEdit\_2" ; qDebug() << text; textEditPtr\_DEBUG->append(text); } else { text = "Did not find any QTextEdit"; qDebug() << text; } // ?? what why ?? text = " DEBUG START DEBUG trace with textEdit\_2" ; textEditPtr\_DEBUG->append(text); crash - null pointer here ??
At line 1 you (try to) create a pointer to some object. At line 2 you test if that object is NULL, and if it is not, then you execute lines 4 to 10 If the object is NULL, then you skip to line 14 But then at line 19 you try to use a pointer which you may already have determined is NULL. Unfortunately the debug output you have shown above does not match that code, so I am making some assumptions here. [edit] Also it does not help you to have the same debug message in two different places. [/edit]
Richard MacCutchan wrote:
If the object is NULL, then you skip to line 14
The OP shows the posted output. For example the following line.
" Sucess Found textEdit "
So line 5 is being executed (and the other lines in that block by the rest of the output.) Of course the code is still wrong if the null pointer does show up.
Richard MacCutchan wrote:
the debug output you have shown above does not match that code
Perhaps that is the actual problem. They think they are running the code shown but the code being executed is different. I have had that happen to me. Often enough that I probably do compiles, cleans and builds far more often than is needed.
-
Richard MacCutchan wrote:
If the object is NULL, then you skip to line 14
The OP shows the posted output. For example the following line.
" Sucess Found textEdit "
So line 5 is being executed (and the other lines in that block by the rest of the output.) Of course the code is still wrong if the null pointer does show up.
Richard MacCutchan wrote:
the debug output you have shown above does not match that code
Perhaps that is the actual problem. They think they are running the code shown but the code being executed is different. I have had that happen to me. Often enough that I probably do compiles, cleans and builds far more often than is needed.
jschell wrote:
Perhaps that is the actual problem. They think they are running the code shown but the code being executed is different.
Given who I suspect is asking the question I am not at all surprised. And if you look at OP's reply to Dave Kreskowiak you will see more confusion.