简体   繁体   English

Qt中新实例化的组件未在插槽中检测到

[英]component is not detecting in slot with new instantiation in Qt

application in Qt 5.2.1. Qt 5.2.1中的应用程序。 here is interface :- 这是界面:-

在此处输入图片说明

Here is goto cell dialog header file :- 这是转到单元格对话框的头文件:

#ifndef GOTOCELLDIALOG_H
#define GOTOCELLDIALOG_H

#include <QDialog>
#include <QtWidgets>

namespace Ui {
class gotocellDialog;
}

class gotocellDialog : public QDialog
{
    Q_OBJECT

public:
explicit gotocellDialog(QWidget *parent = 0);
~gotocellDialog();

private slots:
void on_lineEditCellLocation_textChanged(const QString &arg1);

private:
    Ui::gotocellDialog *ui;
};

#endif // GOTOCELLDIALOG_H

and here is gotocell.cpp 这是gotocell.cpp

#include "gotocelldialog.h"
#include "ui_gotocelldialog.h"

gotocellDialog::gotocellDialog(QWidget *parent) :
    QDialog(parent),
ui(new Ui::gotocellDialog)
{
     ui->setupUi(this);

     ui->pushButtonOK->setEnabled(false);
     QRegExp regexp("[A-Za-z][1-9][0-9]{0,2}");
     ui->lineEditCellLocation->setValidator(new QRegExpValidator(regexp, this));

 }

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

 void gotocellDialog::on_lineEditCellLocation_textChanged(const QString &arg1)
 {ui->pushButtonOK->setEnabled(ui->lineEditCellLocation->hasAcceptableInput());
 }

here another file mainwindow creating new gotocell object but unable to access its(gotocell's) component lineEditCellLocation 这是另一个文件主窗口,它创建新的gotocell对象,但无法访问其gotocell的组件lineEditCellLocation

void spMainWindow::gotocell()
{
     gotocelldlg = new gotocellDialog(this);
     if(gotocelldlg->exec())
     {
          QString str = gotocelldlg->lineEditCellLocation->text.toUpper();
    spsheet->setCurrentCell(str.mid(1).toInt() - 1,
                                      str[0].unicode() - 'A');
     }
 }

here error is showing as :- 这里的错误显示为:

/opt/project/Qt/spreadsheet/spmainwindow.cpp:81: error: 'class  gotocellDialog' has no member named 'lineEditCellLocation'
 /opt/project/Qt/spreadsheet/spmainwindow.cpp:-1: In member function 'void spMainWindow::sort()':

here i want to access gotocelldialog's lineEditCellLocation but unable to get access. 在这里我想访问gotocelldialog的lineEditCellLocation但无法访问。

I think, that this is just a small typo: 我认为,这只是一个小错字:

Replace the following line 替换以下行

QString str = gotocelldlg->lineEditCellLocation->text.toUpper();

with

QString str = ui->lineEditCellLocation->text.toUpper();

For your next posts you should include a minimal reproducible examples. 对于您的下一篇文章,您应该包括一个最小的可复制示例。 This also includes the post of your ui file. 这还包括您的ui文件的发布。 Otherwise, it is very difficult for others to reproduce your problem. 否则,他人很难重现您的问题。

finally i got its solution i did like this :-\\ 终于我得到了它的解决方案,我做到了:-\\

 gotocelldlg = new gotocellDialog(this);
  if(gotocelldlg->exec())
  {
    QLineEdit *ledit = findChild<QLineEdit*>("lineEditCellLocation");

    QString str = ledit->text().toUpper();

    spsheet->setCurrentCell(str.mid(1).toInt() - 1,
                                      str[0].unicode() - 'A');
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM