PDA

View Full Version : Qt4.5 windows TextFind tutorial not working



czlowiekcien
25th May 2009, 08:21
I`m sorry but really i tryed everything. in comment are ways how I tryed. is compiling, text editor is filled in text but button not working as well cursor is not changing.
every widget is add in creator, how to make connect() working?

widget.cpp
//************************************************** ************
#include <QtCore/QFile>
#include <QtCore/QTextStream>
#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
: QWidget(parent), ui(new Ui::Widget)
{
ui->setupUi(this);
loadTextFile();
//QObject::connect(ui->pushButton,SIGNAL(clicked()),this,SLOT(huj()));
//connect(ui->pushButton,SIGNAL(clicked()),this,SLOT(huj()));
//QMetaObject::connectSlotsByName(this);
}

Widget::~Widget()
{
delete ui;
}
void Widget::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);
}
void Widget::on_pushButton_clicked()
{//ui->label->text()="huj";
QString searchString = ui->lineEdit->text();
ui->textEdit->find(searchString, QTextDocument::FindWholeWords);
}
void Widget::huj()
{//ui->label->text()="huj";
QString searchString = ui->lineEdit->text();
ui->textEdit->find(searchString, QTextDocument::FindWholeWords);
}


widget.h
//************************************************** *********
#ifndef WIDGET_H
#define WIDGET_H

#include <QtGui/QWidget>

namespace Ui
{
class Widget;
}
class Widget : public QWidget
{
Q_OBJECT

public:
Widget(QWidget *parent = 0);
~Widget();

public slots:
void on_pushButton_clicked();
void huj();
private:
Ui::Widget *ui;

void loadTextFile();
//void QMetaObject::connectSlotsByName(ui);
};
#endif // WIDGET_H

wysota
25th May 2009, 08:25
QLabel::text() is a getter, not a setter. The code shouldn't even compile.

czlowiekcien
25th May 2009, 08:30
so I commented that and also this is not working

wysota
25th May 2009, 08:33
Do you get any warnings in the console about the connect() statements? How do you know the code doesn't work?

czlowiekcien
25th May 2009, 08:41
QObject::connect(ui->pushButton,SIGNAL(clicked()),this,SLOT(huj()));
this is compiling but nothing happens when I press the button, the button even not going down (is freeze).
QObject::connect(ui->pushButton,SIGNAL(clicked()),ui,SLOT(huj()));

is saying "no maching function for call..."
in creator I cant set connection by clicking becouse he didnt see my slots

I have good news
QObject::connect(ui->lineEdit,SIGNAL(returnPressed()),this,SLOT(huj())) ;

this is working, but why manualy connected button with signal clicked not working? and why on_pushButton_clicked() is not connecting automatycaly even if I use //QMetaObject::connectSlotsByName(this);

that metod is the last method in setupUi so i dont must to type it. what is wrong here?

wysota
25th May 2009, 08:50
Can we see the whole message you are getting?

czlowiekcien
25th May 2009, 09:16
when i using
QObject::connect(ui->pushButton,SIGNAL(clicked()),ui,SLOT(huj()));

widget.cpp:12: error: no matching function for call to `Widget::connect(QPushButton*&, const char*, Ui::Widget*&, const char*)'

M:/Qt/projekty/textfajnd/TextFind/../../../2009.02/qt/include/QtCore/../../src/corelib/kernel/qobject.h:202: note: candidates are: static bool QObject::connect(const QObject*, const char*, const QObject*, const char*, Qt::ConnectionType)

M:/Qt/projekty/textfajnd/TextFind/../../../2009.02/qt/include/QtCore/../../src/corelib/kernel/qobject.h:308: note: bool QObject::connect(const QObject*, const char*, const char*, Qt::ConnectionType) const


that is working well
QObject::connect(ui->lineEdit,SIGNAL(returnPressed()),this,SLOT(huj())) ;

czlowiekcien
25th May 2009, 12:53
now I`m confused 7 hour of searching what is wrong for nothing. I create another button and it was working fine so I check properties and was everething the same so I delete first button and create it again and it is working. so admin can close that subject. thanks for helping

wysota
25th May 2009, 16:15
Hmm... you said it was working well - I thought you found the problem. If not then I can tell you what was wrong - "ui" is not a widget thus passing "ui" as the third parameter to connect() is illegal.

czlowiekcien
25th May 2009, 16:45
I type ui there becouse I trying to find any way to solve my problem I know that was wrong but I still dont know why I had that problem. maybe Qt Creator is not the best tool

wysota
25th May 2009, 19:22
Qt Creator is just a text editor, it doesn't make syntax errors - you do :)