Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. Same code but Qt Creator showed error, Visual Studio didn't

Same code but Qt Creator showed error, Visual Studio didn't

Scheduled Pinned Locked Moved Solved Qt Creator and other tools
qt creator c++visual studioerror
5 Posts 3 Posters 583 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.
  • B Offline
    B Offline
    bpbp241
    wrote on 18 Aug 2023, 14:59 last edited by
    #1

    Hi, this is my first post in the forum :)

    I'm using Qt Creator 10.0.2, Qt 6.2.2 MSVC2019 static compiler.
    I got a class named ProcessData it has overloaded operators like this (in Process.h header file):

        bool operator== (const ProcessData & rhs) const;
        bool operator== (const tagPROCESSENTRY32 & rhs) const;
        bool operator== (const tagPROCESSENTRY32W & rhs) const;
    

    In source file (Process.cpp), I also implemented the overloaded functions there, and then the error occurred in this line:

            auto & current_entry = *list[i];
            if (current_entry != entries[i]){
            //code
    }
    

    current_entry is type of ProcessData, and entries is a vector of tagPROCESSENTRY32W, Qt Creator fails to detect it and returns this error C2678:
    4feabbb0-205c-4d32-9067-b1e3c8223081-image.png

    But VS2019 works perfectly fine:
    a5d50950-1e2f-48d1-8fec-ab9cc60e1dc8-image.png

    So, what am I missing here, or this is the Creator's bug, If I'm missing something, please help me to fix it, thank you very much. I really want to use QTC to continue my work but this error slows me down for few days recently.

    And in my header file, it always fades out the code like this:
    de5e9fed-a417-4c96-b942-c946fab0fa95-image.png

    Is this normal?

    C 1 Reply Last reply 18 Aug 2023, 15:11
    0
    • B bpbp241
      18 Aug 2023, 14:59

      Hi, this is my first post in the forum :)

      I'm using Qt Creator 10.0.2, Qt 6.2.2 MSVC2019 static compiler.
      I got a class named ProcessData it has overloaded operators like this (in Process.h header file):

          bool operator== (const ProcessData & rhs) const;
          bool operator== (const tagPROCESSENTRY32 & rhs) const;
          bool operator== (const tagPROCESSENTRY32W & rhs) const;
      

      In source file (Process.cpp), I also implemented the overloaded functions there, and then the error occurred in this line:

              auto & current_entry = *list[i];
              if (current_entry != entries[i]){
              //code
      }
      

      current_entry is type of ProcessData, and entries is a vector of tagPROCESSENTRY32W, Qt Creator fails to detect it and returns this error C2678:
      4feabbb0-205c-4d32-9067-b1e3c8223081-image.png

      But VS2019 works perfectly fine:
      a5d50950-1e2f-48d1-8fec-ab9cc60e1dc8-image.png

      So, what am I missing here, or this is the Creator's bug, If I'm missing something, please help me to fix it, thank you very much. I really want to use QTC to continue my work but this error slows me down for few days recently.

      And in my header file, it always fades out the code like this:
      de5e9fed-a417-4c96-b942-c946fab0fa95-image.png

      Is this normal?

      C Offline
      C Offline
      cristian-adam
      wrote on 18 Aug 2023, 15:11 last edited by
      #2

      Does your project build with Qt Creator? Is this just a syntax highlighting error?

      Your project should build in the same way with Qt Creator and Visual Studio.

      process.h is controversial and Qt Creator itself has had this issue:

      #if defined(Q_CC_MINGW) && defined(WIN_PTHREADS_H) && !defined(_INC_PROCESS)
        // Arrived here via <pthread.h> which wants to include <process.h>
        #include_next <process.h>
      #elif !defined(UTILS_PROCESS_H)
      #define UTILS_PROCESS_H
      

      At the top of Qt Creator's utils/process.h. Maybe you can figure something out.

      B 2 Replies Last reply 18 Aug 2023, 16:06
      1
      • C cristian-adam
        18 Aug 2023, 15:11

        Does your project build with Qt Creator? Is this just a syntax highlighting error?

        Your project should build in the same way with Qt Creator and Visual Studio.

        process.h is controversial and Qt Creator itself has had this issue:

        #if defined(Q_CC_MINGW) && defined(WIN_PTHREADS_H) && !defined(_INC_PROCESS)
          // Arrived here via <pthread.h> which wants to include <process.h>
          #include_next <process.h>
        #elif !defined(UTILS_PROCESS_H)
        #define UTILS_PROCESS_H
        

        At the top of Qt Creator's utils/process.h. Maybe you can figure something out.

        B Offline
        B Offline
        bpbp241
        wrote on 18 Aug 2023, 16:06 last edited by
        #3

        @cristian-adam Thanks, I changed the name of the header file as well as the source file, and it didn't fade out anymore.

        But the error about overloaded operator still occurs, maybe I should manually overload "!=" operator?

        1 Reply Last reply
        0
        • C cristian-adam
          18 Aug 2023, 15:11

          Does your project build with Qt Creator? Is this just a syntax highlighting error?

          Your project should build in the same way with Qt Creator and Visual Studio.

          process.h is controversial and Qt Creator itself has had this issue:

          #if defined(Q_CC_MINGW) && defined(WIN_PTHREADS_H) && !defined(_INC_PROCESS)
            // Arrived here via <pthread.h> which wants to include <process.h>
            #include_next <process.h>
          #elif !defined(UTILS_PROCESS_H)
          #define UTILS_PROCESS_H
          

          At the top of Qt Creator's utils/process.h. Maybe you can figure something out.

          B Offline
          B Offline
          bpbp241
          wrote on 18 Aug 2023, 16:16 last edited by
          #4

          @cristian-adam My project is built with Qt Creator, but the code itself is in another project compiled with VS using Qt, and when opening that project, the code compiled without any error.

          C 1 Reply Last reply 18 Aug 2023, 16:34
          0
          • C Christian Ehrlicher moved this topic from General and Desktop on 18 Aug 2023, 16:18
          • B bpbp241
            18 Aug 2023, 16:16

            @cristian-adam My project is built with Qt Creator, but the code itself is in another project compiled with VS using Qt, and when opening that project, the code compiled without any error.

            C Online
            C Online
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on 18 Aug 2023, 16:34 last edited by
            #5

            When you want to use the operator !=() you have to provide it - a compiler can not simply create the operator!=() from the operator==().

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            1 Reply Last reply
            2
            • B bpbp241 has marked this topic as solved on 15 Sept 2023, 01:10

            5/5

            18 Aug 2023, 16:34

            • Login

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