如何在不同的Qt插件中从QLineEdit获取文本

时间:2017-03-15 14:37:01

标签: c++ qt interface qlineedit qtplugin

我有一个界面MyInterface

class MyInterface
{

public:
    virtual ~MyInterface() {}

    virtual QMap<QString, QString> *inputsMap() const = 0;
};

我有一个实现MyInterface MyImplementingClass 类。但是,我无法从QLineEdit *fullNames获取文字:

QLineEdit *fullNames = new QLineEdit();

QMap<QString, QString> *MyImplementingClass::inputsMap() const
{
    QMap<QString, QString> *map = new QMap<QString, QString>();
    map -> insert("fullNames", this -> fullNames -> text());
    map -> insert("coolText", "This works OK");
    return map;
}

ImplementorsCollector中我收集了实现MyInterface的所有插件:

void ImplementorsCollector :: initImplementors(QObject *plugin)
{
    MyInterface *iMyInterface = qobject_cast<MyInterface *>(plugin);
    if (iMyInterface)
        myObject = iMyInterface -> inputsMap();
}

但是,仍在ImplementorsCollector

/* This prints nothing. Nothing gets passed from **QLineEdit *fullNames** */

if (myObject -> contains("fullNames"))
qDebug() << "fullNames : " << myObject -> value("fullNames");

/* This prints OK */

if (myObject -> contains("coolText"))
qDebug() << "coolText : " << myObject -> value("coolText");

如何从其他插件获取**QLineEdit *fullNames**的文本输入?

提前谢谢大家。

0 个答案:

没有答案