Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. called pointer is null...

called pointer is null...

Scheduled Pinned Locked Moved C / C++ / MFC
help
9 Posts 5 Posters 19 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    SOLVED Thanks to all contributors who help to find the issue.

    K D L 3 Replies Last reply
    0
    • L Lost User

      SOLVED Thanks to all contributors who help to find the issue.

      K Offline
      K Offline
      k5054
      wrote on last edited by
      #2

      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 above

      Keep Calm and Carry On

      1 Reply Last reply
      0
      • L Lost User

        SOLVED Thanks to all contributors who help to find the issue.

        D Offline
        D Offline
        Dave Kreskowiak
        wrote on last edited by
        #3

        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

        L 1 Reply Last reply
        0
        • D 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

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          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
          
          D 1 Reply Last reply
          0
          • L Lost User

            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
            
            D Offline
            D Offline
            Dave Kreskowiak
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            • L Lost User

              SOLVED Thanks to all contributors who help to find the issue.

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              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]

              CPalliniC J 2 Replies Last reply
              0
              • L Lost User

                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]

                CPalliniC Offline
                CPalliniC Offline
                CPallini
                wrote on last edited by
                #7

                Pretty good assumptions, I believe.

                "In testa che avete, Signor di Ceprano?" -- Rigoletto

                In testa che avete, signor di Ceprano?

                1 Reply Last reply
                0
                • L Lost User

                  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]

                  J Offline
                  J Offline
                  jschell
                  wrote on last edited by
                  #8

                  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.

                  L 1 Reply Last reply
                  0
                  • J jschell

                    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.

                    L Offline
                    L Offline
                    Lost User
                    wrote on last edited by
                    #9

                    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.

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups