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. How to get QT Creator to recognize std::chrono_literals?
Forum Updated to NodeBB v4.3 + New Features

How to get QT Creator to recognize std::chrono_literals?

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 4 Posters 5.0k Views 2 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.
  • S Offline
    S Offline
    Stoke
    wrote on last edited by
    #1

    Hello, I created this simple program

    #include <stdio.h>
    #include <thread>
    #include <chrono>
    using namespace std;
    
    int main(int argc, char *argv[])
    {
        using namespace std::chrono_literals;
        this_thread::sleep_for(10s);
        cout << "Hello World!" << endl;
        return 0;
    }
    

    Qt tells me

    expected token ';' got '<error>'
    

    on the line which uses 10s chrono literal.
    I can actually compile the project fine with no issues, run it, and everything works. The IDE itself does not however recognize this. How do I get QT creator recognize this syntax as valid?

    Note I'm using a QT creator c++ console application using cmake. I have no .pro file because of this.

    jsulmJ 1 Reply Last reply
    0
    • S Stoke

      Hello, I created this simple program

      #include <stdio.h>
      #include <thread>
      #include <chrono>
      using namespace std;
      
      int main(int argc, char *argv[])
      {
          using namespace std::chrono_literals;
          this_thread::sleep_for(10s);
          cout << "Hello World!" << endl;
          return 0;
      }
      

      Qt tells me

      expected token ';' got '<error>'
      

      on the line which uses 10s chrono literal.
      I can actually compile the project fine with no issues, run it, and everything works. The IDE itself does not however recognize this. How do I get QT creator recognize this syntax as valid?

      Note I'm using a QT creator c++ console application using cmake. I have no .pro file because of this.

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

      @Stoke said in How to get QT Creator to recognize std::chrono_literals?:

      Qt tells me

      For sure not: Qt isn't a compiler.
      Where exactly do you get this? I guess in QtCreator?
      You can try to activate ClangStaticAnalyzer (go to "Help/About Pligins...").

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

      S 1 Reply Last reply
      0
      • jsulmJ jsulm

        @Stoke said in How to get QT Creator to recognize std::chrono_literals?:

        Qt tells me

        For sure not: Qt isn't a compiler.
        Where exactly do you get this? I guess in QtCreator?
        You can try to activate ClangStaticAnalyzer (go to "Help/About Pligins...").

        S Offline
        S Offline
        Stoke
        wrote on last edited by Stoke
        #3

        @jsulm said in How to get QT Creator to recognize std::chrono_literals?:

        For sure not: Qt isn't a compiler.

        @jsulm yes it does, you want me to screen shot this for you? QT creator, the IDE, definitively tells me "expected token ';' got '<error>'" and underlines this section (this_thread::sleep_for(10s);), even though compilation and execution works fine, I don't know what QT uses internally to recognize this, but the parser is not recgonizing this as proper syntax with in QT.

        @jsulm said in How to get QT Creator to recognize std::chrono_literals?:

        Where exactly do you get this? I guess in QtCreator?

        Yes? did I imply something else? I said in the title and in the post itself I get this in QT Creator. Here is what is happening http://imgur.com/a/XEwrY, as you can see i compile and run fine, QT just doesn't understand the syntax.

        @jsulm said in How to get QT Creator to recognize std::chrono_literals?:

        You can try to activate ClangStaticAnalyzer (go to "Help/About Pligins...").

        It is already activated.

        mrjjM 1 Reply Last reply
        0
        • S Stoke

          @jsulm said in How to get QT Creator to recognize std::chrono_literals?:

          For sure not: Qt isn't a compiler.

          @jsulm yes it does, you want me to screen shot this for you? QT creator, the IDE, definitively tells me "expected token ';' got '<error>'" and underlines this section (this_thread::sleep_for(10s);), even though compilation and execution works fine, I don't know what QT uses internally to recognize this, but the parser is not recgonizing this as proper syntax with in QT.

          @jsulm said in How to get QT Creator to recognize std::chrono_literals?:

          Where exactly do you get this? I guess in QtCreator?

          Yes? did I imply something else? I said in the title and in the post itself I get this in QT Creator. Here is what is happening http://imgur.com/a/XEwrY, as you can see i compile and run fine, QT just doesn't understand the syntax.

          @jsulm said in How to get QT Creator to recognize std::chrono_literals?:

          You can try to activate ClangStaticAnalyzer (go to "Help/About Pligins...").

          It is already activated.

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Stoke

          Ahh, i see . It's not compiler error you get but Qt Creator's flagging of
          invalid stuff ? ( its syntax checker) ( it has red line and if u tooltip it says the error ?)

          alt text

          Maybe it will be fixed in later version , especially if you you can open bug report.

          S 1 Reply Last reply
          0
          • mrjjM mrjj

            @Stoke

            Ahh, i see . It's not compiler error you get but Qt Creator's flagging of
            invalid stuff ? ( its syntax checker) ( it has red line and if u tooltip it says the error ?)

            alt text

            Maybe it will be fixed in later version , especially if you you can open bug report.

            S Offline
            S Offline
            Stoke
            wrote on last edited by
            #5

            @mrjj Yes the syntax checker doesn't properly parse them.

            Also it was already reported nearly a year ago, I'm probably going to leave QT creator for now since I can't guarantee base modern C++ support. Its strange since you can use chrono literals in other qt constructs, so the idea that they can't parse in the IDE them seems a bit odd.

            mrjjM _ 2 Replies Last reply
            0
            • S Stoke

              @mrjj Yes the syntax checker doesn't properly parse them.

              Also it was already reported nearly a year ago, I'm probably going to leave QT creator for now since I can't guarantee base modern C++ support. Its strange since you can use chrono literals in other qt constructs, so the idea that they can't parse in the IDE them seems a bit odd.

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by mrjj
              #6

              @Stoke ¨
              So it will not color it red in other constructs ?
              I have not used literal much yet.

              Hmm, its Not Evaluated still. So nope, no fix anytime soon.

              I agree its annoying as u grow to trust the red lines.

              S 1 Reply Last reply
              0
              • mrjjM mrjj

                @Stoke ¨
                So it will not color it red in other constructs ?
                I have not used literal much yet.

                Hmm, its Not Evaluated still. So nope, no fix anytime soon.

                I agree its annoying as u grow to trust the red lines.

                S Offline
                S Offline
                Stoke
                wrote on last edited by
                #7

                @mrjj I'm not sure it has issue with user defined literals, but those are c++11, as well, I haven't noticed it with other standard c++11 constructs or c++14 libraries (it will, for example, not understand what std::chrono_literals are if I set cmake file to use c++11 explicitly, but if I use c++14 or what ever Cmake does by default, it knows that at least std::chrono_literals exists). This piece of code auto lambda = [](auto a, auto b) { return a * b; }; which is apparently only valid in c++14 for example is not marked is wrong. So I think this is just a lack of support for parsing literals that don't have _ prefix (ie those introduced in c++14)

                1 Reply Last reply
                1
                • S Stoke

                  @mrjj Yes the syntax checker doesn't properly parse them.

                  Also it was already reported nearly a year ago, I'm probably going to leave QT creator for now since I can't guarantee base modern C++ support. Its strange since you can use chrono literals in other qt constructs, so the idea that they can't parse in the IDE them seems a bit odd.

                  _ Offline
                  _ Offline
                  _PIB
                  wrote on last edited by _PIB
                  #8

                  @Stoke Clang Code model is not enabled by default for whatever reason. I opened several bugs and many of them were closed after saying that Clang Code Model fixes it and your bug report is closed for same reason.

                  Qt is probably making a full transition to Clang code model. Use "Hlp->About plugins" to enable it, restart.

                  S 1 Reply Last reply
                  1
                  • _ _PIB

                    @Stoke Clang Code model is not enabled by default for whatever reason. I opened several bugs and many of them were closed after saying that Clang Code Model fixes it and your bug report is closed for same reason.

                    Qt is probably making a full transition to Clang code model. Use "Hlp->About plugins" to enable it, restart.

                    S Offline
                    S Offline
                    Stoke
                    wrote on last edited by
                    #9

                    @_PIB That seems to have worked, weird I remember looking and seeing it was enabled before...

                    1 Reply Last reply
                    0

                    • Login

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