Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. What is the difference between Run and Debug in QtCreator?
Forum Updated to NodeBB v4.3 + New Features

What is the difference between Run and Debug in QtCreator?

Scheduled Pinned Locked Moved Unsolved General and Desktop
18 Posts 3 Posters 5.7k Views
  • 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.
  • P Offline
    P Offline
    Pauly
    wrote on last edited by Pauly
    #3

    cmd is just QString with only ASCII characters, such as "capture image".

    I print out data.lpData in Run mode and Debug mode. It is strange that for Run mode it is something like 0x4bd1568 regardless what command is sent (checked data.cbData which is the right amount of characters to be sent). For Debug mode it is something like 0x4d0ae08 and it is different for different command and it is different even for sending then same command.

    The application seems to get the command right in Run mode, but not in Debug mode.

    I'm totally confused how this should work...

    jsulmJ 1 Reply Last reply
    0
    • P Pauly

      cmd is just QString with only ASCII characters, such as "capture image".

      I print out data.lpData in Run mode and Debug mode. It is strange that for Run mode it is something like 0x4bd1568 regardless what command is sent (checked data.cbData which is the right amount of characters to be sent). For Debug mode it is something like 0x4d0ae08 and it is different for different command and it is different even for sending then same command.

      The application seems to get the command right in Run mode, but not in Debug mode.

      I'm totally confused how this should work...

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #4

      @Pauly 0x4bd1568 looks like a pointer. Do you print the pointer or the string the pointer is pointing to?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2
      • P Offline
        P Offline
        Pauly
        wrote on last edited by
        #5

        Can you give me some hint how can I print that as string? Thanks.

        jsulmJ 1 Reply Last reply
        0
        • P Pauly

          Can you give me some hint how can I print that as string? Thanks.

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by jsulm
          #6

          @Pauly

          qDebug() << data.lpData;
          

          should do
          How do you print it out now?

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • VRoninV Offline
            VRoninV Offline
            VRonin
            wrote on last edited by VRonin
            #7

            Good old hungarian notation makes it clear that lpData is a pointer and you are passing a pointer to a temporary variable to it so it can't work.

            LPCTSTR dataString = new TCHAR [cmd.size()+1];
             for(int i=0i<cmd.size();++i)
            dataString[i]= static_cast<TCHAR>(cmd.at(i).unicode());
            dataString[cmd.size()]=static_cast<TCHAR>('\0');
            COPYDATASTRUCT data;
            data.dwData = 0x267811;
            data.cbData = cmd.size()+1;
            data.lpData = dataString;
            DWORD lpdwResult;
            LRESULT err = SendMessageTimeout(hwnd, WM_COPYDATA, 0, (LPARAM)&data, SMTO_ABORTIFHUNG, 2000, &lpdwResult); //WM_COPYDATA
            delete [] dataString;
            

            "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
            ~Napoleon Bonaparte

            On a crusade to banish setIndexWidget() from the holy land of Qt

            P 1 Reply Last reply
            1
            • P Offline
              P Offline
              Pauly
              wrote on last edited by Pauly
              #8
              qDebug() << data.lpData;
              

              was what I used. It seems to print the pointer...

              so i did some searching and used

              char* a=(char *)data.lpData;
              for (int i=0; i<data.cbData; ++i) {
                  qDebug() << *a ;
                  ++a;
              }
              

              I can see that in Run mode the characters are correct. And in Debug mode it is a bunch of garbage, so it fails. So why would this be different in debug mode?

              1 Reply Last reply
              0
              • VRoninV VRonin

                Good old hungarian notation makes it clear that lpData is a pointer and you are passing a pointer to a temporary variable to it so it can't work.

                LPCTSTR dataString = new TCHAR [cmd.size()+1];
                 for(int i=0i<cmd.size();++i)
                dataString[i]= static_cast<TCHAR>(cmd.at(i).unicode());
                dataString[cmd.size()]=static_cast<TCHAR>('\0');
                COPYDATASTRUCT data;
                data.dwData = 0x267811;
                data.cbData = cmd.size()+1;
                data.lpData = dataString;
                DWORD lpdwResult;
                LRESULT err = SendMessageTimeout(hwnd, WM_COPYDATA, 0, (LPARAM)&data, SMTO_ABORTIFHUNG, 2000, &lpdwResult); //WM_COPYDATA
                delete [] dataString;
                
                P Offline
                P Offline
                Pauly
                wrote on last edited by
                #9

                @VRonin said in What is the difference between Run and Debug in QtCreator?:

                data.lpData = dataString;

                I'm getting a bunch of errors. What should I do?

                191: error: assignment of read-only location '*(dataString + ((sizetype)(((unsigned int)i) * 2u)))'
                dataString[i] = static_cast<TCHAR>(cmd.at(i).unicode());
                ^

                192: error: assignment of read-only location '(dataString + ((sizetype)(((unsigned int)cmd.QString::size()) * 2u)))'
                dataString[cmd.size()]=static_cast<TCHAR>('\0');
                ^
                error: invalid conversion from 'const void
                ' to 'PVOID {aka void*}' [-fpermissive]
                data.lpData = dataString;
                ^

                1 Reply Last reply
                0
                • VRoninV Offline
                  VRoninV Offline
                  VRonin
                  wrote on last edited by VRonin
                  #10

                  sorry, didn't realise LPCTSTR (I too failed at reading hungarian notation) is defined as const, just replace it with LPTSTR or with TCHAR* or with auto

                  "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                  ~Napoleon Bonaparte

                  On a crusade to banish setIndexWidget() from the holy land of Qt

                  P 1 Reply Last reply
                  2
                  • VRoninV VRonin

                    sorry, didn't realise LPCTSTR (I too failed at reading hungarian notation) is defined as const, just replace it with LPTSTR or with TCHAR* or with auto

                    P Offline
                    P Offline
                    Pauly
                    wrote on last edited by
                    #11

                    @VRonin said in What is the difference between Run and Debug in QtCreator?:

                    sorry, didn't realise LPCTSTR (I too failed at reading hungarian notation) is defined as const, just replace it with LPTSTR or with TCHAR* or with auto

                    Thanks for the note. So I change the code to:

                    TCHAR* dataString = new TCHAR [cmd.size()+1];
                    for(int i=0; i<cmd.size();++i)
                        dataString[i] = static_cast<TCHAR>(cmd.at(i).unicode());
                    dataString[cmd.size()]=static_cast<TCHAR>('\0');
                    
                    
                    COPYDATASTRUCT data;
                    data.dwData = MAGIC;
                    data.cbData = cmd.size()+1;
                    data.lpData = dataString;
                    char* a=(char *)data.lpData;
                    
                    for (int i=0; i<data.cbData; ++i) {
                        qDebug() << *a ;
                        ++a;
                    }
                    DWORD lpdwResult;
                    LRESULT err = SendMessageTimeout(hwnd, WM_COPYDATA, 0, (LPARAM)&data, SMTO_ABORTIFHUNG, 2000, &lpdwResult); //WM_COPYDATA
                    

                    I can see the cmd being printed out (only half of cmd thought) but debug mode still failed. Target application now seems to get the first character of cmd, just as if I send QString* or QString.toLatin1().data().

                    I guess the question comes down to, what is the difference in QString::toLocal8bit().data() in Run mode and Debug mode?

                    VRoninV 1 Reply Last reply
                    0
                    • P Pauly

                      @VRonin said in What is the difference between Run and Debug in QtCreator?:

                      sorry, didn't realise LPCTSTR (I too failed at reading hungarian notation) is defined as const, just replace it with LPTSTR or with TCHAR* or with auto

                      Thanks for the note. So I change the code to:

                      TCHAR* dataString = new TCHAR [cmd.size()+1];
                      for(int i=0; i<cmd.size();++i)
                          dataString[i] = static_cast<TCHAR>(cmd.at(i).unicode());
                      dataString[cmd.size()]=static_cast<TCHAR>('\0');
                      
                      
                      COPYDATASTRUCT data;
                      data.dwData = MAGIC;
                      data.cbData = cmd.size()+1;
                      data.lpData = dataString;
                      char* a=(char *)data.lpData;
                      
                      for (int i=0; i<data.cbData; ++i) {
                          qDebug() << *a ;
                          ++a;
                      }
                      DWORD lpdwResult;
                      LRESULT err = SendMessageTimeout(hwnd, WM_COPYDATA, 0, (LPARAM)&data, SMTO_ABORTIFHUNG, 2000, &lpdwResult); //WM_COPYDATA
                      

                      I can see the cmd being printed out (only half of cmd thought) but debug mode still failed. Target application now seems to get the first character of cmd, just as if I send QString* or QString.toLatin1().data().

                      I guess the question comes down to, what is the difference in QString::toLocal8bit().data() in Run mode and Debug mode?

                      VRoninV Offline
                      VRoninV Offline
                      VRonin
                      wrote on last edited by VRonin
                      #12

                      @Pauly said in What is the difference between Run and Debug in QtCreator?:

                      char* a=(char *)data.lpData;

                      Are you sure lpData is char and not wchar?

                      instead of

                      char* a=(char *)data.lpData;
                      
                      for (int i=0; i<data.cbData; ++i) {
                          qDebug() << *a ;
                          ++a;
                      }
                      
                      

                      try printing it using

                      #if defined(UNICODE) || defined(_UNICODE)
                      std::wcout
                      #else
                      std::cout
                      #endif
                      << static_cast<TCHAR*>(data.lpData);
                      

                      what is the difference in QString::toLocal8bit().data() in Run mode and Debug mode?

                      QString::toLocal8bit() returns a temporary QByteArray, .data() returns a pointer to the internal data of that temporary variable. That pointer becomes invalid as soon as the temporary variable gets destroyed (i.e. a line below). The debug mode might just keep that variable alive for longer lo let you see inside it if you needed to

                      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                      ~Napoleon Bonaparte

                      On a crusade to banish setIndexWidget() from the holy land of Qt

                      P 1 Reply Last reply
                      0
                      • VRoninV VRonin

                        @Pauly said in What is the difference between Run and Debug in QtCreator?:

                        char* a=(char *)data.lpData;

                        Are you sure lpData is char and not wchar?

                        instead of

                        char* a=(char *)data.lpData;
                        
                        for (int i=0; i<data.cbData; ++i) {
                            qDebug() << *a ;
                            ++a;
                        }
                        
                        

                        try printing it using

                        #if defined(UNICODE) || defined(_UNICODE)
                        std::wcout
                        #else
                        std::cout
                        #endif
                        << static_cast<TCHAR*>(data.lpData);
                        

                        what is the difference in QString::toLocal8bit().data() in Run mode and Debug mode?

                        QString::toLocal8bit() returns a temporary QByteArray, .data() returns a pointer to the internal data of that temporary variable. That pointer becomes invalid as soon as the temporary variable gets destroyed (i.e. a line below). The debug mode might just keep that variable alive for longer lo let you see inside it if you needed to

                        P Offline
                        P Offline
                        Pauly
                        wrote on last edited by
                        #13

                        @VRonin

                        Where could I see the output as printing it your way? I'm running this at QtCreator and I can't figure out where the output goes. Thanks.

                        jsulmJ 1 Reply Last reply
                        1
                        • P Pauly

                          @VRonin

                          Where could I see the output as printing it your way? I'm running this at QtCreator and I can't figure out where the output goes. Thanks.

                          jsulmJ Offline
                          jsulmJ Offline
                          jsulm
                          Lifetime Qt Champion
                          wrote on last edited by
                          #14

                          @Pauly "Application output" tab

                          https://forum.qt.io/topic/113070/qt-code-of-conduct

                          P 1 Reply Last reply
                          1
                          • jsulmJ jsulm

                            @Pauly "Application output" tab

                            P Offline
                            P Offline
                            Pauly
                            wrote on last edited by
                            #15

                            @jsulm

                            I see that now. Yes, it is the cmd that I'm trying to send. However the application still does not get it...

                            1 Reply Last reply
                            0
                            • VRoninV Offline
                              VRoninV Offline
                              VRonin
                              wrote on last edited by
                              #16

                              How does the application expect the command? UTF-16, UTF-8, ASCII?

                              "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                              ~Napoleon Bonaparte

                              On a crusade to banish setIndexWidget() from the holy land of Qt

                              1 Reply Last reply
                              0
                              • P Offline
                                P Offline
                                Pauly
                                wrote on last edited by
                                #17

                                I think UTF8, since .toLocal8bit() is the only thing that works, even in Run mode...

                                1 Reply Last reply
                                0
                                • VRoninV Offline
                                  VRoninV Offline
                                  VRonin
                                  wrote on last edited by
                                  #18

                                  ok then, back to the basic:

                                  void MyClass::SendCmd(HWND hwnd, QString cmd)
                                  {
                                  const QByteArray utf8Cmd = cmd.toUtf8();
                                  COPYDATASTRUCT data;
                                  data.dwData = 0x267811;
                                  data.cbData = cmd.size()+1;
                                  data.lpData = utf8Cmd.data();
                                  DWORD lpdwResult;
                                  LRESULT err = SendMessageTimeout(hwnd, WM_COPYDATA, 0, (LPARAM)&data, SMTO_ABORTIFHUNG, 2000, &lpdwResult); //WM_COPYDATA
                                  }
                                  

                                  @Pauly said in What is the difference between Run and Debug in QtCreator?:

                                  I think UTF8, since .toLocal8bit() is the only thing that works

                                  toLocal8bit not necessarily == toUtf8

                                  "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                                  ~Napoleon Bonaparte

                                  On a crusade to banish setIndexWidget() from the holy land of Qt

                                  1 Reply Last reply
                                  1

                                  • Login

                                  • Login or register to search.
                                  • First post
                                    Last post
                                  0
                                  • Categories
                                  • Recent
                                  • Tags
                                  • Popular
                                  • Users
                                  • Groups
                                  • Search
                                  • Get Qt Extensions
                                  • Unsolved