获取QDialog中的Set值 [英] Get the Set values in QDialog

查看:78
本文介绍了获取QDialog中的Set值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有部分ID,数量和数量的对话框表格。价钱。我需要将这些值从我的主窗体传递到对话框。我通过谷歌找到了一些我尝试过的建议。一种方法是添加吸气剂和放大器。 setter方法。我能够在dialog.exec之前设置值但是如何让这些值显示在dailog中?



这是我的editorderline.h





I have a Dialog form with a part id,qty, & Price. I need to pass values for these from my main form to the dialog. I found a couple suggestions via google which I've tried. One way was to add getters & setters. I was able to set the values before dialog.exec but how do I get these values to display in the dailog?

Here is my editorderline.h


#ifndef EDITORDERLINE_H
#define EDITORDERLINE_H

#include <QDialog>
#include "Globals.h"
#include "helpers.h"
#include <part.h>
namespace Ui {
class EditOrderLine;
}

class EditOrderLine : public QDialog
{
    Q_OBJECT

public:

    void setPart(const QString &part);
    void setPartKey (const int &partkey);
    void setPartName(const QString &partname);
    void setQty (const int &qty);
    void setPrice(const double &price);
    <pre lang="C#">QString getPart();
public:
    explicit EditOrderLine(QWidget *parent = 0);
    ~EditOrderLine();

private:
    Ui::EditOrderLine *ui;
    QString m_part;
    QString m_partname;
    int m_partkey;
    int m_qty;
    double m_price;

};

#endif // EDITORDERLINE_H</pre>

<pre lang="text">



这是editorderline.cpp




Here is the editorderline.cpp

<pre lang="C++">

&lt;pre&gt;#include &quot;editorderline.h&quot;
#include &quot;ui_editorderline.h&quot;

EditOrderLine::EditOrderLine(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::EditOrderLine)
{

    ui-&amp;gt;setupUi(this);
      
    qDebug()&amp;lt;&amp;lt;&quot;m_part = &quot; &amp;lt;&amp;lt;m_part;
    qDebug()&amp;lt;&amp;lt;&quot;getPart = &quot; &amp;lt;&amp;lt;getPart();
    qDebug()&amp;lt;&amp;lt;&quot;this-&amp;gt;m_part = &quot; &amp;lt;&amp;lt; this-&amp;gt;m_part;



}

EditOrderLine::~EditOrderLine()
{
    delete ui;
}

void EditOrderLine::setPart(const QString &amp;amp;part)
{     
    m_part = part;

}
QString EditOrderLine::getPart()
{

    return m_part;

}
void EditOrderLine::setPartName(const QString &amp;amp;partname)
{
    m_partname = partname;
}

void EditOrderLine::setPartKey (const int &amp;amp;partkey)
{
    m_partkey = partkey;
}
void EditOrderLine::setQty(const int &amp;amp;qty)
{
    m_qty = qty;
}
void EditOrderLine::setPrice(const double &amp;amp;price)
{
    m_price = price;
}&lt;/pre&gt;
<pre lang="text">



正如您在上面所看到的,我使用了一些调试语句来尝试查看show以访问部件ID的值,但每种方式都返回空白。怎么做呢?


As you can see above I've used a few debug statements to try to see show to access the values for part id but each way returns blank. How can this be done?

推荐答案

问题是你试图在构造函数中显示值。在创建对话框对象之前,在调用getter和setter以及exec()函数之前调用构造函数。



显示对话框时(带有exec) function)值应该在表格上。
The problem is that you are trying to show the values in the constructor. The constructor is called when the dialog object is created, before you call the getters and setters and the exec() function.

When the dialog is displayed (with the exec function) the values should be on the form.


这篇关于获取QDialog中的Set值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆