替换QDockWidget的小部件而不删除之前的内容

时间:2018-02-22 12:16:21

标签: c++ qt

我想替换QDockWidget *的widget(QWidget *),但是调用setWidget(),删除以前的widget。如何防止这种删除?

QDockWidget* dw = new QDockWidget;
QWidget* tw1 = new TestWidget;
QWidget* tw2 = new TestWidget;
dw->setWidget(tw1);
dw->setWidget(tw2); // tw1 deleted here
delete dw;
// I want to use tw1 here, but it died

TestWidget只是一个检查删除时刻的测试:

class TestWidget : public QWidget {
public:
    TestWidget(QWidget* parent = nullptr)
        : QWidget(parent)
    {
        cout << "TestWidget() " << this << endl;
    }
    ~TestWidget() override {
        cout << "~TestWidget() " << this << endl;
    }
};

1 个答案:

答案 0 :(得分:1)

foreach ($xpath->query("//product/ElectricSpecifications[contains(., ' $value')]") as $item) {
    list($numbers) = explode('MHz', $item->textContent);
    list($a, $b) = explode(' - ', $numbers);
    echo $a ; // 2310
    echo $b ; // 2485
    $item->nodeValue = "$a, $b" ; // save content

    // or :
    preg_match_all('~(\d+)~', $item->textContent, $matches);
    $item->nodeValue = implode(", ", $matches[0]);
}