• 5666阅读
  • 5回复

[原创]试着运行QT creator 帮助文件的Tutorial,竟然出错 [复制链接]

上一主题 下一主题
离线ebony
 
只看楼主 倒序阅读 楼主  发表于: 2011-02-01
请帮着看看,到底为错在哪里,看了好久,找不到错误啊。

Running build steps for project testTextFinder...
Configuration unchanged, skipping qmake step.
Starting: "C:/Qt/mingw/bin/mingw32-make.exe" -w
mingw32-make: Entering directory `C:/Qt/zcsTest/testTextFinder-build-desktop'
C:/Qt/mingw/bin/mingw32-make -f Makefile.Debug
mingw32-make[1]: Entering directory `C:/Qt/zcsTest/testTextFinder-build-desktop'
g++ -c -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I"..\..\qt\include\QtCore" -I"..\..\qt\include\QtGui" -I"..\..\qt\include" -I"..\..\qt\include\ActiveQt" -I"debug" -I"." -I"..\testTextFinder" -I"." -I"..\..\qt\mkspecs\win32-g++" -o debug\testtextfinder.o ..\testTextFinder\testtextfinder.cpp
..\testTextFinder\testtextfinder.cpp: In constructor 'testTextFinder::testTextFinder(QWidget*)':
..\testTextFinder\testtextfinder.cpp:11: error: 'loadTextFile' was not declared in this scope
..\testTextFinder\testtextfinder.cpp: At global scope:
..\testTextFinder\testtextfinder.cpp:25: error: no 'void testTextFinder::loadTextFile()' member function declared in class 'testTextFinder'
mingw32-make[1]: Leaving directory `C:/Qt/zcsTest/testTextFinder-build-desktop'
mingw32-make: Leaving directory `C:/Qt/zcsTest/testTextFinder-build-desktop'
mingw32-make[1]: *** [debug/testtextfinder.o] Error 1
mingw32-make: *** [debug] Error 2
The process "C:/Qt/mingw/bin/mingw32-make.exe" exited with code %2.
Error while building project testTextFinder (target: Desktop)
When executing build step 'Make'
=================================================================================
我仔细查看过,只是将tutorial里的类的名字: TextFinder 改为TestTextFinder



离线ebony
只看该作者 1楼 发表于: 2011-02-01
testTextFinder.cpp
============================================================
#include "testtextfinder.h"
#include "ui_testtextfinder.h"
#include <QtCore/QFile>
#include <QtCore/QTextStream>

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

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

void testTextFinder::on_findButton_clicked()
{
    QString searchString = ui->lineEdit->text();
    ui->textEdit->find(searchString, QTextDocument::FindWholeWords);
}

void testTextFinder::loadTextFile()
{
     QFile inputFile(":/input.txt");
     inputFile.open(QIODevice::ReadOnly);

     QTextStream in(&inputFile);
     QString line = in.readAll();
     inputFile.close();

     ui->textEdit->setPlainText(line);
     QTextCursor cursor = ui->textEdit->textCursor();
     cursor.movePosition(QTextCursor::Start, QTextCursor::MoveAnchor, 1);
}
离线ebony
只看该作者 2楼 发表于: 2011-02-01
#ifndef TESTTEXTFINDER_H
#define TESTTEXTFINDER_H

#include <QWidget>

namespace Ui {
    class testTextFinder;
}

class testTextFinder : public QWidget
{
    Q_OBJECT

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

private:
    Ui::testTextFinder *ui;
    void loadTextFinder();

private slots:
    void on_findButton_clicked();
};

#endif // TESTTEXTFINDER_H
离线jdwx

只看该作者 3楼 发表于: 2011-02-01
最好不要改类名,很麻烦的。改的时候用查找替换方法还方便一点,看错误信息估计是还有一部分没改过来。
还有就是不要把自己的程序放到QT目录下!就是QT自己带的例子在原来的目录里都不能被正确编译,移到其它目录里就能编译。就是一点经验。
[ 此帖被jdwx在2011-02-01 10:16重新编辑 ]
发帖时要说明:操作系统、Qt版本、编译器,这样能更快的得到回复。
离线ebony
只看该作者 4楼 发表于: 2011-02-01
但我用了CTRL+F查找,应该全部改过来了. 而且,该TUTORIAL的.h文件只有一个, .cpp也不过就两个, 都是很少的代码.

实在看不出来哪里还有没改过来的类名字.

难道QT会自己生成隐藏的库? 即便如此, 我建项目的时候, 就已经将名字改为TestTextFinder了,它也应该按照新名字生成吧.

离线jdwx

只看该作者 5楼 发表于: 2011-02-04
#include "ui_testtextfinder.h"这个文件改了吗?改这个有点麻烦,它是由UI生成的,还是在UI文件里改吧!
发帖时要说明:操作系统、Qt版本、编译器,这样能更快的得到回复。
快速回复
限100 字节
 
上一个 下一个