Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. [SOLVED] std::string and Q_PROPERTY()
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] std::string and Q_PROPERTY()

Scheduled Pinned Locked Moved C++ Gurus
3 Posts 2 Posters 2.6k 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.
  • A Offline
    A Offline
    ASxa86
    wrote on last edited by
    #1

    I am unable to get std::string properties for my custom widget to appear in QtDesigner.

    Below is an example of the code i'm running that isn't working. Any suggestions?

    @
    // CustomCheckBox.h
    #pragma once
    #include <QtWidgets/QCheckBox>

    #include <string>

    Q_DECLARE_METATYPE(std::string)

    class CustomCheckBox : public QCheckBox
    {
    Q_OBJECT
    // this property does NOT appear in QtDesigner
    Q_PROPERTY(std::string name READ getName WRITE setName)

     public:
          CustomCheckBox(QWidget* parent = nullptr);
          virtual ~CustomCheckBox();
    
          void setName(const std::string& x);
          std::string getName() const;
    
     private:
          std::string name;
    

    };
    @

    @
    // CustomCheckBox.cpp
    #include "CustomCheckBox.h"

    CustomCheckBox::CustomCheckBox(QWidget* parent) : QCheckBox(parent)
    {
    // doesn't work
    qRegisterMetaTypestd::string();

     // doesn't work
     qRegisterMetaType<std::string>("std::string");
    

    }
    @

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mcosta
      wrote on last edited by
      #2

      Hi,

      std::string is a template specification (some kind of typedef).
      I think that Q_PROPERTY doesn't workfor templates (check on the documentation).

      Anyway IMHO it's better to use QString as property.

      Once your problem is solved don't forget to:

      • Mark the thread as SOLVED using the Topic Tool menu
      • Vote up the answer(s) that helped you to solve the issue

      You can embed images using (http://imgur.com/) or (http://postimage.org/)

      1 Reply Last reply
      0
      • A Offline
        A Offline
        ASxa86
        wrote on last edited by
        #3

        I...should have known that. Thank you. Using QString will probably be what I do now.

        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