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. template typename enum as default value

template typename enum as default value

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 370 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
    Silvia-V
    wrote on last edited by
    #1

    use QVariant::Invalid as template default value

        template <typename T, typename V = QVariant::Invalid>
        T *registerExServiceStp2(const ServiceType &type, void (T::*func)(const V &) = nullptr) {
            Service *service = typeToService(type);
            if (!service)
                return nullptr;
            if (!service->token()) {
                T *token = new T(service);
                if (func)
                    (token->*func)(service->extraInfo().value<V>());
                service->token(token);
                emit moduleStatusChanged(type);
            }
            return dynamic_cast<T *>(service->token());
        }
    

    but get this

    error: ‘Invalid’ in ‘class QVariant’ does not name a type
    line: template <typename T, typename V = typename QVariant::Invalid>
    

    how should i fix it

    1 Reply Last reply
    0
    • jeremy_kJ Online
      jeremy_kJ Online
      jeremy_k
      wrote on last edited by jeremy_k
      #2

      QVariant::Invalid is a value for the type QVariant::Type. template <typename T, QVariant::Type V = QVariant::Invalid> is probably what you're looking for. The other uses of V should to be updated in the same manner.

      Asking a question about code? http://eel.is/iso-c++/testcase/

      1 Reply Last reply
      3
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi
        Maybe

        template <typename T, typename V = QVariant() >
        ....
        

        if the intent was to have V be an invalid QVariant pr default if not specified.

        S 1 Reply Last reply
        4
        • mrjjM mrjj

          Hi
          Maybe

          template <typename T, typename V = QVariant() >
          ....
          

          if the intent was to have V be an invalid QVariant pr default if not specified.

          S Offline
          S Offline
          Silvia-V
          wrote on last edited by
          #4

          @mrjj Thank you. It really worked out with this method

          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