qstring.h no such file or directory error!
hello i am trying to get this program work but it returns me error
QString.h no such file or directory error!
here is the code
Code:
#ifndef PUSHBUTTON_H
#define PUSHBUTTON_H
#include <QPushButton>
#include <QString> //here is where its showing error
{
Q_OBJECT
public:
public slots:
void updatenewvalues()
{
if(this->text() == "Don't click me!")
{
setText("Click me!");
return;
}
setText("Don't click me!");
}
};
#endif // PUSHBUTTON_H
Code:
int main(int argc, char* argv[])
{
PushButton clickme("Click me!");
clickme.resize(200, 30);
QObject::connect(&clickme,
SIGNAL(clicked
()),
&clickme,
SLOT(updatenewvalues
()));
clickme.show();
return app.exec();
}
Thanks!
Re: qstring.h no such file or directory error!
Hmm everything seems OK,moreover this #include QString isn't necessary.
What is not fully right done is the connection of the signal.Move it into constructor of your class.
Show us compilation output please.
Re: qstring.h no such file or directory error!
connection of the signal???due to mean like this
Code:
PushButton::PushButton()
{
QObject::connect(&clickme,
SIGNAL(clicked
()),
&clickme,
SLOT(updatenewvalues
()));
}
i am new to c++ but i can write few codes since i already have experience with c
Re: qstring.h no such file or directory error!
Sort of, use "this" in place of "&clickme" (which will not compile anyway). You have two possible constructors (neither is parameterless) so you need to be sure that the connection gets made regardless of which is called (or eliminate one if you will never use it).
Re: qstring.h no such file or directory error!
ok here is it i have rewritten everything from the beginning
Code:
#ifndef PUSHBUTTON_H
#define PUSHBUTTON_H
#include <QPushButton.h>
{
Q_OBJECT
{
QObject::connect(this,
signal(clicked
()),
this,
slot(change
()));
}
public slots:
void change()
{
if(this->text() == "Don't click me!")
{
setText("Click me!");
return;
}
setText("Don't click me!");
}
}
#endif
Code:
#include <QApplication>
#include "pushbutton.h"
int main(int argc, char* argv[])
{
pushbutton button = new pushbutton("Dont click me");
button.show();
return app.exec();
}
these are the following errors that shows me
Code:
C:\Documents and Settings\t\My Documents\project\frontend\pushbutton.h|6|error: expected class-name before 'class'|
C:\Documents and Settings\t\My Documents\project\frontend\pushbutton.h|6|error: expected '{' before 'class'|
C:\Documents and Settings\t\My Documents\project\frontend\pushbutton.h|6|error: redefinition of 'class QPushButton'|
C:\Qt\2010.03\qt\include\QtGui\..\..\src\gui\widgets\qpushbutton.h|58|error: previous definition of 'class QPushButton'|
C:\Documents and Settings\t\My Documents\project\frontend\pushbutton.h|6|error: new types may not be defined in a return type|
C:\Documents and Settings\t\My Documents\project\frontend\pushbutton.h|6|note: (perhaps a semicolon is missing after the definition of '<type error>')|
C:\Documents and Settings\t\My Documents\project\frontend\main.cpp|5|error: two or more data types in declaration of 'main'|
||=== Build finished: 6 errors, 0 warnings ===|
please help me Thanks!
Re: qstring.h no such file or directory error!
You forgot the semicolon after class declaration.
edit: and your class' constructor is private now, add public: before definition of constructor
Re: qstring.h no such file or directory error!
ok thanks for the reply i have added the ';' after class declaration and public: to the constructor but still the problems occur
Code:
C:\Documents and Settings\t\My Documents\project\frontend\pushbutton.h|6|error: expected class-name before 'class'|
C:\Documents and Settings\t\My Documents\project\frontend\pushbutton.h|6|error: expected '{' before 'class'|
C:\Documents and Settings\t\My Documents\project\frontend\pushbutton.h|6|error: redefinition of 'class QPushButton'|
C:\Qt\2010.03\qt\include\QtGui\..\..\src\gui\widgets\qpushbutton.h|58|error: previous definition of 'class QPushButton'|
C:\Documents and Settings\t\My Documents\project\frontend\pushbutton.h|26|error: multiple types in one declaration|
C:\Documents and Settings\t\My Documents\project\frontend\main.cpp||In function 'int main(int, char**)':|
C:\Documents and Settings\t\My Documents\project\frontend\main.cpp|8|error: variable 'pushbutton button' has initializer but incomplete type|
C:\Documents and Settings\t\My Documents\project\frontend\main.cpp|8|error: invalid use of incomplete type 'class pushbutton'|
C:\Documents and Settings\t\My Documents\project\frontend\pushbutton.h|6|error: forward declaration of 'class pushbutton'|
||=== Build finished: 8 errors, 0 warnings ===|
Re: qstring.h no such file or directory error!
Inheritance requires the public, protected or private keywords, not class
Code:
class pushbutton
: public /*private or protected, not class*/ QPushButton{
Q_OBJECT
{
QObject::connect(this,
signal(clicked
()),
this,
slot(change
()));
}
...
Better start with good C++ book before programming with Qt.
Re: qstring.h no such file or directory error!
its showing error in this code
Code:
{
QObject::connect(this,
SIGNAL(clicked
()),
this,
SLOT(change
()));
}
its showing error in this part
Code:
obj\Debug\main.o||In function `pushbutton':|
C:\Documents and Settings\t\My Documents\project\frontend\pushbutton.h|11|undefined reference to `vtable for pushbutton'|
C:\Documents and Settings\t\My Documents\project\frontend\pushbutton.h|11|undefined reference to `vtable for pushbutton'|
||=== Build finished: 2 errors, 0 warnings ===|
i know that its basic c++ but i am more into C if i get this signal and slot part correct then i will be rolling :-)
Re: qstring.h no such file or directory error!
Is the class header on the list of HEADERS in .pro file ? Check if you have moc_pushbutton.cpp somewhere in the build directories. I think the header is not moc'ed, so you get undefined references, make sure its in the list of HEADERS and run qmake/make again.
Btw. you don't have to use QObject:: for connections, pushbutton class is derived from QObject, so you can simply call connect(...).
Re: qstring.h no such file or directory error!
Quote:
Originally Posted by
wenn32
Code:
pushbutton button = new pushbutton("Dont click me");
Better start with learning C++ first. It is an absolute must for using Qt.
It is either:
Code:
pushbutton *button = new pushbutton("...");
or
Code:
pushbutton button("...");
Re: qstring.h no such file or directory error!
Quote:
Originally Posted by
stampede
Is the class header on the list of HEADERS in .pro file ? Check if you have moc_pushbutton.cpp somewhere in the build directories. I think the header is not moc'ed, so you get undefined references, make sure its in the list of HEADERS and run qmake/make again.
Btw. you don't have to use QObject:: for connections, pushbutton class is derived from QObject, so you can simply call connect(...).
i am using code blocks IDE and i didn't find any .pro file in the project folder.so should i create a .pro file to get rid of the error??
Re: qstring.h no such file or directory error!
here is the main.cpp
Code:
#include <QApplication>
#include "pushbutton.h"
int main(int argc, char* argv[])
{
pushbutton *button = new pushbutton("Dont click me");
button->show();
return app.exec();
}
here is the pushbutton.h
Code:
#ifndef PUSHBUTTON_H_
#define PUSHBUTTON_H_
#include <QPushButton>
{
Q_OBJECT
public:
{
connect(this,SIGNAL(clicked()),this,SLOT(change()));
}
public slots:
void change()
{
if(this->text() == "Don't click me!")
{
setText("Click me!");
return;
}
setText("Don't click me!");
}
};
#endif
ok i did some research and this is what i did
first i runned the qmake -project with folder source as my project folder like
Code:
c:/document......../myproject>qmake -project
then i got .pro file which has following data
Code:
##Automatically generated by qmake (2.01a) Thu May 5 16:40:27 2011#####
TEMPLATE = app
TARGET =
DEPENDPATH += .
INCLUDEPATH += .
# Input
HEADERS += pushbutton.h
SOURCES += main.cpp
but still after doing that i am getting error as
Code:
obj\Debug\main.o||In function `pushbutton':|
C:\Documents and Settings\t\My Documents\project\sample\pushbutton.h|11|undefined reference to `vtable for pushbutton'|
C:\Documents and Settings\t\My Documents\project\sample\pushbutton.h|11|undefined reference to `vtable for pushbutton'|
||=== Build finished: 2 errors, 0 warnings ===|
i am using code blocks IDE.
Now can you guys help me.where am i doing wrong?????
i also did qmake -makefile and got few makefiles even that is not solving the problem.
Re: qstring.h no such file or directory error!
I've never used codeblocks, maybe its generating it's own Makefiles. Leave the IDE build system for now, good that you try to use the tools by hand - this way you can learn a lot more than by clicking on the IDE gui buttons.
Try to cleanup all Makefiles in your project directories, run qmake --project again, then qmake and make. Code looks ok, so I guess this is caused by some leftovers in build directories.
Re: qstring.h no such file or directory error!
Finally it works! if you just search all the threads i have started.you will see that all my threads where on signals and slots and now it works can't believe it!!!!!
anyways i am really feeling bad that i couldn't make it work with code blocks(it would have been easier)
anyways i have written a program that will do QMAKE -project,QMAKE & MAKE(when placed in the project file)(that's less burden!!!)
so thanks to all the people who helped me THANKS!