1

我是编程和使用 qt 创建自己的 GUI 的新手。我正在尝试将搜索栏作为我的列表视图之一,但它一直说没有可以调用的匹配函数......这可能是一个非常愚蠢的问题。这是我的代码。

void Widget::on_SearchBar_textChanged(const QString &arg1)
{

    QString Input;
    ui->Online->find(Input);
}

和错误

C:\Qt\Qt5.1.1\Tools\QtCreator\bin\CryptoCourier\widget.cpp:21: 错误: 没有匹配函数调用 'QListWidget::find(QString&)'

ui->Online->find(Input);

这是我要求的其余代码

好的所以这是我的其余代码。不多,但在这里。

#include "widget.h"
#include "ui_CryptoCC.h"
#include <QString>

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

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

void Widget::on_SearchBar_textChanged(const QString &arg1)
{
   #include <string>
    QString Input;
    ui->Online->find(Input);
}
                       ^
4

1 回答 1

3

你有两个主要问题:

  • #include语句应该在函数之外,因为它们实际上包含了你放置它们的位置的整个文件。
  • 对于QString,您要包含的文件可能称为“QString”。

尝试这样的事情:

#include <QString>

/* the rest of your code, which you didn't include in your example */

void Widget::on_SearchBar_textChanged(const QString &arg1)
{
    /* by the way, you're calling Online->find() with an empty string,
     * did you mean to use `arg1` here? */
    QString Input;
    ui->Online->find(Input);
}

除此之外,我需要知道什么uiui->Online是什么,然后我才能给你建议你可以调用什么函数。

于 2013-10-15T00:24:32.990 回答