Connect() wont work!
-
hi, i mad an pie chart which doesn't say what each color is:D but i can include that, just dont want yet
i made an app which uses piechart(made by me one) to analys QString and show it in a chart:
the problem is my TextChanged(Qstring) wont run when i change text, not even when i add another button and bind it to it !
heres code:
@#include "Win.h"
#include <QVBoxLayout>Window::Window(QWidget *parent)
: QWidget (parent)
{
pie = new Donut(this);
pie->setSize(250);//QWidget *wid = new QWidget(this); QVBoxLayout *vbox = new QVBoxLayout(); LineEdit = new QLineEdit(this); LineEdit->setText("Enter Text here"); qreal digits = 0; qreal letters = 0; qreal spaces = 0; qreal puncts = 0; foreach(QChar s, LineEdit->text()) { if (s.isDigit()) { digits++; } else if (s.isLetter()) { letters++; } else if (s.isSpace()) { spaces++; } else if (s.isPunct()) { puncts++; } } pie->AddPie(digits/LineEdit->text().count()*100,QColor(200,0,10)); pie->AddPie(spaces/LineEdit->text().count()*100,QColor(10,0,200)); pie->AddPie(letters/LineEdit->text().count()*100,QColor(0,200,10)); pie->AddPie(puncts/LineEdit->text().count()*100,QColor(10,250,200)); vbox->addWidget(pie); vbox->addWidget(LineEdit); setLayout(vbox); //setCentralWidget(wid); connect(LineEdit, SIGNAL(textChanged(QString)), this, SLOT(TextChanged(QString)));
}
void Window::TextChanged(QString text)
{foreach(QChar s, text) { if (s.isDigit()) { digits++; } else if (s.isLetter()) { letters++; } else if (s.isSpace()) { spaces++; } else if (s.isPunct()) { puncts++; } } pie->clearPies(); pie->AddPie(digits/text.count()*100,QColor(200,0,10)); pie->AddPie(spaces/text.count()*100,QColor(10,0,200)); pie->AddPie(letters/text.count()*100,QColor(0,200,10)); pie->AddPie(puncts/text.count()*100,QColor(10,250,200));
}@ win.cpp
win.h:
@#ifndef WIN_H
#define WIN_H#include <QWidget>
#include <QLineEdit>
#include <QPushButton>
#include <QLabel>
#include "donut.h"class Window : public QWidget
{
public:
Window(QWidget *parent = 0);
private slots:
void TextChanged(QString text);
private:
Donut *pie;
QLineEdit *LineEdit;
qreal digits;
qreal letters;
qreal spaces;
qreal puncts;
};#endif
@i thinked a lot can't find the problem !!!! :( i just give up!
-
Is lineEdit shown ? Did you enter some text in linEdit ? Put some debugs in slots and ensure that slot is indeed called. Here I don't see any issue at all with code.
-
Hi,
Do you see any errors on runtime ?
Is TextChanged(QString text) declared as a slot ?
Try putting some debug statements in TextChanged(QString text) to check if the slot is entered. -
Hi,
One thing that looks wrong is your header name. Why is it Win.h and your class name Window ?
In any case it's a bad idea to have a class with that name, it might easily clash with something on Windows
-
no errors im not sure how to put debug but i google it now!
SGaist: i made many projects with headerfiler name diffrent from class anme and it worked :\ i think they aren't support to be same :O
i entered many texts hit enter re typed ttryed many things, text is shown in it!
renamed them to window.h and .cpp still wont work, i get the pie chart correctly, and stats are correct, but my Slot wont be collect on text change or buttom push, tryed many diffrent Widgets and slots and items, non worked!
-
wait, i reopened QtCreator this time, and after re loading it now i get error:
QObject::connect: No such slot QWidget::TextChanged(QString) in ..\PieChart\window.cpp:49i didnt used to.
but i have the Text Changed slot in both .h and .cpp file, why is qtCreator making this error :o
-
The problem is the missing Q_OBJECT macro from the Window class declaration:
@//...
class Window : public QWidget
{
Q_OBJECT
public:
//...@ -
[quote author="Zlatomir" date="1403612099"]The problem is the missing Q_OBJECT macro from the Window class declaration:
@//...
class Window : public QWidget
{
Q_OBJECT
public:
//...@[/quote]silly mistake ! but still after including it it didnt work, still gives same error:
QObject::connect: No such slot QWidget::TextChanged(QString) in ..\PieChart\window.cpp:49
-
Make sure you renamed the files in the project file too, and run qmake and then build your project.
-
[quote author="Zlatomir" date="1403613053"]Make sure you renamed the files in the project file too, and run qmake and then build your project.[/quote]
i did but i always used the play green button on Qtcreator to make my projects im not sure what Qmake is
-
In the Build menu you have Run qmake use that and only after that build your project.
-
some weird thing:
i made another project exactly copy pasted the codes there, it didnt give the error but still didn't work,
now my old project wont work gives error:
C:\Qt\Qt5.3.0\Tools\QtCreator\bin\PieChart\window.h:10: error: undefined reference to `vtable for Window'
-
06:03:53: Running steps for project PieChart...
06:03:53: Starting: "C:\Qt\Qt5.3.0\5.3\mingw482_32\bin\qmake.exe" C:\Qt\Qt5.3.0\Tools\QtCreator\bin\PieChart\PieChart.pro -r -spec win32-g++ "CONFIG+=debug"
06:03:54: The process "C:\Qt\Qt5.3.0\5.3\mingw482_32\bin\qmake.exe" exited normally.
06:03:54: Elapsed time: 00:00.nothing happened
damn it why didn't it work:(
-
please check with simple example of lineEdit. See how it works. I suggest you clean everything and rebuild your application. If you want to me to check send me the complete project. I can check and revert to you.
-
[quote author="Dheerendra" date="1403619438"]please check with simple example of lineEdit. See how it works. I suggest you clean everything and rebuild your application. If you want to me to check send me the complete project. I can check and revert to you.[/quote]
sorry my code is so long i can't send it:( (in a post)
i thought a lot nothing seems wrong , if you have time, how can i send it to you :( -
Ok i fixed the connect ! but problem is ,i can't use pie->clearPies() in the slot:( it doesn't do it when i change text, it only shows that slot is triggered