查看完整版本: [-- Qt官方范例中,使用QUiLoader加载UI文件,结合插件的问题。 --]

QTCN开发网 -> Qt基础编程 -> Qt官方范例中,使用QUiLoader加载UI文件,结合插件的问题。 [打印本页] 登录 -> 注册 -> 回复主题 -> 发表主题

caiwei_cs 2017-08-04 14:54

Qt官方范例中,使用QUiLoader加载UI文件,结合插件的问题。

官方范例1:Calculator Builder Example 中有如下代码:
  1. QUiLoader loader;

        QFile file(":/forms/calculatorform.ui");
        file.open(QFile::ReadOnly);
        QWidget *formWidget = loader.load(&file, this);
        file.close();

        ui_inputSpinBox1 = findChild<QSpinBox*>("inputSpinBox1");
        ui_inputSpinBox2 = findChild<QSpinBox*>("inputSpinBox2");
        ui_outputWidget = findChild<QLabel*>("outputWidget");

实现了,动态加载UI文件,并且通过findChild查找到UI文件中的控件,能够对控件做进一步的操作。

官方范例2:World Time Clock Builder Example 中也用QUiLoader加载UI文件,并且文件中包含插件生成的控件,WorldTimeClock(插件在官方范例 World Time Clock Plugin Example中生成)。我希望像第一个范例一样,能够查找并使用UI文件中的控件。

  1. QFile file(":/forms/form.ui");
        file.open(QFile::ReadOnly);

        QWidget *widget = loader.load(&file);
    //自己加入—begin
    //qt自带控件可以
        QLabel_currentTime = widget->findChild<QLabel*>("label");

        qDebug()<<ui_label_currentTime->text();
        ui_label_currentTime->setText("lala");

        //插件加入的控件,报错
        WorldTimeClock * ui_clock;
        ui_clock = widget->findChild<WorldTimeClock*>("worldTimeClock");
        qDebug()<<ui_clock->metaObject()->className();
        ui_clock->setTimeZone(2);
    //自己加入-end

        file.close();
        widget->show();
范例位置:$$[QT_INSTALL_EXAMPLES]/designer/worldtimeclockbuilder
报错:
D:\Qt\Qt5.5.1\Examples\Qt-5.5\designer\worldtimeclockbuilder\main.cpp:77: error: undefined reference to `_imp___ZN14WorldTimeClock11setTimeZoneEi'

虽然我将生成插件的工程中的头文件应用过来,或者拷贝过来还是不行。
//#include "../../../../Examples/Qt-5.5/designer/worldtimeclockplugin/worldtimeclock.h"
#include "worldtimeclock.h"

我想问的是
如何实现对UI文件中插件控件,例如上面的worldtimeclock,也能像自带控件一样修改被引用使用。否则觉得灵活性太差,用插件没什么意义。

另外:用插件生成的控件,只能在QDesigner中使用,在QtCreator中不行?好像在哪里看到,Qt原版用vs编译的,所以mingw下QDesignerCustomWidgetInterface插件是不能在Qtcreator中用?



查看完整版本: [-- Qt官方范例中,使用QUiLoader加载UI文件,结合插件的问题。 --] [-- top --]



Powered by phpwind v8.7 Code ©2003-2011 phpwind
Gzip disabled