帮我调试一下 - 从'const char*'到'char*'的无效转换

Sco*_*ott 0 c++ const

我根本不明白为什么会出现这个错误.

Widget.cpp: In constructor 'Widget::Widget(Generic, char*, int, int, int, QObject*)':
Widget.cpp:13: error: invalid conversion from 'const char*' to 'char*'
Run Code Online (Sandbox Code Playgroud)

就Widget的构造函数而言,我没有任何'const char*'.

class Widget: public QObject {
    Q_OBJECT
    Q_PROPERTY(char *col READ getCol WRITE setCol)
    Q_PROPERTY(char *row READ getRow WRITE setRow)
    Generic visitor;
    char *_name;
    char *_widget_base;
    int _row;
    int _col;
    int _type;
    public:
    Widget(Generic visitor, char *name, int row, int col, int type, QObject *parent);
    char* widgetBase() const;
    QString getCol() const;
    void setCol(const QString &col);
    QString getRow() const;
    void setRow(const QString &row);

};

Widget::Widget(Generic v, char *name, int row, int col, int type, 
    QObject *parent = 0 ) {
    visitor = v;
    std::string str(name);
    int pos1 = str.find(":");
    int pos2 = str.rfind(":");
    _widget_base = str.substr(pos1, pos2-pos1).c_str();
    _name = name;
    _row = row;
    _col = col;
    _type = type;
}
Run Code Online (Sandbox Code Playgroud)

Ste*_*ham 5

这是一个const char *价值

str.substr(pos1, pos2-pos1).c_str();
Run Code Online (Sandbox Code Playgroud)