2013-10-14 150 views
1

我是編程和使用qt創建自己的GUI的新手。我試圖讓我的列表視圖的搜索欄之一,但它一直說沒有匹配的函數來調用......這可能是一個非常愚蠢的問題。這是我的代碼。Qt Creator和Qstring

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: error: no matching function for call to '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); 
} 
        ^
+3

您正在調用QListWidget實例'Online'的'find'方法。這個方法在這裏描述:http://qt-project.org/doc/qt-5.0/qtwidgets/qwidget.html#find。它與搜索沒有任何關係,而是將本機窗口小部件句柄映射回QWidgets(並且不需要QString參數)。也許包括一個你想要完成的小UI模型,然後人們將能夠得到更多的幫助。 – ksimons

+2

提示:你不能通過拼湊隨機的東西來編寫程序;首先學習語言,然後學習Qt框架的一些基礎知識,並且總是閱讀你不知道的方法的文檔。 –

+1

噢。我忘了拿出來。我修好了。 – noahdotgansallo

回答

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是之前,我可以給你什麼樣的功能,你可以對他們的來電諮詢。

+1

我轉發了我的完整代碼 – noahdotgansallo

+1

我應該包含UI嗎?這真的很長... – noahdotgansallo