Results 1 to 15 of 15

Thread: qstring.h no such file or directory error!

  1. #1
    Join Date
    Jun 2010
    Posts
    21
    Qt products
    Qt4
    Platforms
    Windows

    Default 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
    Qt Code:
    1. #ifndef PUSHBUTTON_H
    2. #define PUSHBUTTON_H
    3. #include <QPushButton>
    4. #include <QString> //here is where its showing error
    5.  
    6. class PushButton: public QPushButton
    7. {
    8. Q_OBJECT
    9. public:
    10. PushButton(QWidget* parent = 0): QPushButton(parent){}
    11. PushButton(const QString& text, QWidget* parent = 0) : QPushButton(text, parent){}
    12. public slots:
    13. void updatenewvalues()
    14. {
    15. if(this->text() == "Don't click me!")
    16. {
    17. setText("Click me!");
    18. return;
    19. }
    20. setText("Don't click me!");
    21. }
    22. };
    23. #endif // PUSHBUTTON_H
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. int main(int argc, char* argv[])
    2. {
    3. QApplication app(argc, argv);
    4. PushButton clickme("Click me!");
    5. clickme.resize(200, 30);
    6. clickme.setFont(QFont("Times", 18, QFont::Bold));
    7. QObject::connect(&clickme, SIGNAL(clicked()), &clickme, SLOT(updatenewvalues()));
    8. clickme.show();
    9. return app.exec();
    10. }
    To copy to clipboard, switch view to plain text mode 

    Thanks!

  2. #2
    Join Date
    Sep 2008
    Location
    Poland
    Posts
    80
    Thanks
    4
    Thanked 5 Times in 4 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default 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.

  3. #3
    Join Date
    Jun 2010
    Posts
    21
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: qstring.h no such file or directory error!

    connection of the signal???due to mean like this

    Qt Code:
    1. PushButton::PushButton()
    2. {
    3. QObject::connect(&clickme, SIGNAL(clicked()), &clickme, SLOT(updatenewvalues()));
    4. }
    To copy to clipboard, switch view to plain text mode 

    i am new to c++ but i can write few codes since i already have experience with c

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default 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).

  5. #5
    Join Date
    Jun 2010
    Posts
    21
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: qstring.h no such file or directory error!

    ok here is it i have rewritten everything from the beginning

    Qt Code:
    1. #ifndef PUSHBUTTON_H
    2. #define PUSHBUTTON_H
    3. #include <QPushButton.h>
    4. class pushbutton : class QPushButton
    5. {
    6. Q_OBJECT
    7. pushbutton(const QString& text, QWidget* parent = 0) : QPushButton(text, parent)
    8. {
    9. QObject::connect(this,signal(clicked()),this,slot(change()));
    10. }
    11.  
    12. public slots:
    13. void change()
    14. {
    15. if(this->text() == "Don't click me!")
    16. {
    17. setText("Click me!");
    18. return;
    19. }
    20. setText("Don't click me!");
    21. }
    22. }
    23. #endif
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #include <QApplication>
    2. #include "pushbutton.h"
    3.  
    4.  
    5. int main(int argc, char* argv[])
    6. {
    7. QApplication app(argc, argv);
    8. pushbutton button = new pushbutton("Dont click me");
    9.  
    10. button.show();
    11. return app.exec();
    12. }
    To copy to clipboard, switch view to plain text mode 

    these are the following errors that shows me
    Qt Code:
    1. C:\Documents and Settings\t\My Documents\project\frontend\pushbutton.h|6|error: expected class-name before 'class'|
    2.  
    3. C:\Documents and Settings\t\My Documents\project\frontend\pushbutton.h|6|error: expected '{' before 'class'|
    4.  
    5. C:\Documents and Settings\t\My Documents\project\frontend\pushbutton.h|6|error: redefinition of 'class QPushButton'|
    6.  
    7. C:\Qt\2010.03\qt\include\QtGui\..\..\src\gui\widgets\qpushbutton.h|58|error: previous definition of 'class QPushButton'|
    8.  
    9. C:\Documents and Settings\t\My Documents\project\frontend\pushbutton.h|6|error: new types may not be defined in a return type|
    10.  
    11. C:\Documents and Settings\t\My Documents\project\frontend\pushbutton.h|6|note: (perhaps a semicolon is missing after the definition of '<type error>')|
    12.  
    13. C:\Documents and Settings\t\My Documents\project\frontend\main.cpp|5|error: two or more data types in declaration of 'main'|
    14.  
    15. ||=== Build finished: 6 errors, 0 warnings ===|
    To copy to clipboard, switch view to plain text mode 

    please help me Thanks!
    Last edited by wenn32; 4th May 2011 at 10:47.

  6. #6
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default 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

  7. #7
    Join Date
    Jun 2010
    Posts
    21
    Qt products
    Qt4
    Platforms
    Windows

    Default 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

    Qt Code:
    1. C:\Documents and Settings\t\My Documents\project\frontend\pushbutton.h|6|error: expected class-name before 'class'|
    2.  
    3. C:\Documents and Settings\t\My Documents\project\frontend\pushbutton.h|6|error: expected '{' before 'class'|
    4.  
    5. C:\Documents and Settings\t\My Documents\project\frontend\pushbutton.h|6|error: redefinition of 'class QPushButton'|
    6.  
    7. C:\Qt\2010.03\qt\include\QtGui\..\..\src\gui\widgets\qpushbutton.h|58|error: previous definition of 'class QPushButton'|
    8.  
    9. C:\Documents and Settings\t\My Documents\project\frontend\pushbutton.h|26|error: multiple types in one declaration|
    10.  
    11. C:\Documents and Settings\t\My Documents\project\frontend\main.cpp||In function 'int main(int, char**)':|
    12.  
    13. C:\Documents and Settings\t\My Documents\project\frontend\main.cpp|8|error: variable 'pushbutton button' has initializer but incomplete type|
    14.  
    15. C:\Documents and Settings\t\My Documents\project\frontend\main.cpp|8|error: invalid use of incomplete type 'class pushbutton'|
    16.  
    17. C:\Documents and Settings\t\My Documents\project\frontend\pushbutton.h|6|error: forward declaration of 'class pushbutton'|
    18.  
    19. ||=== Build finished: 8 errors, 0 warnings ===|
    To copy to clipboard, switch view to plain text mode 

  8. #8
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: qstring.h no such file or directory error!

    Inheritance requires the public, protected or private keywords, not class
    Qt Code:
    1. class pushbutton : public /*private or protected, not class*/ QPushButton
    2. {
    3. Q_OBJECT
    4. pushbutton(const QString& text, QWidget* parent = 0) : QPushButton(text, parent)
    5. {
    6. QObject::connect(this,signal(clicked()),this,slot(change()));
    7. }
    8. ...
    To copy to clipboard, switch view to plain text mode 
    Better start with good C++ book before programming with Qt.

  9. #9
    Join Date
    Jun 2010
    Posts
    21
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: qstring.h no such file or directory error!

    its showing error in this code
    Qt Code:
    1. pushbutton(const QString& text, QWidget* parent = 0) : QPushButton(text, parent)
    2. {
    3. QObject::connect(this,SIGNAL(clicked()),this,SLOT(change()));
    4. }
    To copy to clipboard, switch view to plain text mode 

    its showing error in this part
    Qt Code:
    1. obj\Debug\main.o||In function `pushbutton':|
    2.  
    3. C:\Documents and Settings\t\My Documents\project\frontend\pushbutton.h|11|undefined reference to `vtable for pushbutton'|
    4.  
    5. C:\Documents and Settings\t\My Documents\project\frontend\pushbutton.h|11|undefined reference to `vtable for pushbutton'|
    6. ||=== Build finished: 2 errors, 0 warnings ===|
    To copy to clipboard, switch view to plain text mode 

    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 :-)

  10. #10
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default 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(...).

  11. #11
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: qstring.h no such file or directory error!

    Quote Originally Posted by wenn32 View Post
    Qt Code:
    1. pushbutton button = new pushbutton("Dont click me");
    To copy to clipboard, switch view to plain text mode 
    Better start with learning C++ first. It is an absolute must for using Qt.

    It is either:
    Qt Code:
    1. pushbutton *button = new pushbutton("...");
    To copy to clipboard, switch view to plain text mode 
    or
    Qt Code:
    1. pushbutton button("...");
    To copy to clipboard, switch view to plain text mode 

  12. #12
    Join Date
    Jun 2010
    Posts
    21
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: qstring.h no such file or directory error!

    Quote Originally Posted by stampede View Post
    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??

  13. #13
    Join Date
    Jun 2010
    Posts
    21
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: qstring.h no such file or directory error!

    here is the main.cpp

    Qt Code:
    1. #include <QApplication>
    2. #include "pushbutton.h"
    3.  
    4. int main(int argc, char* argv[])
    5. {
    6. QApplication app(argc, argv);
    7. pushbutton *button = new pushbutton("Dont click me");
    8.  
    9. button->show();
    10. return app.exec();
    11. }
    To copy to clipboard, switch view to plain text mode 

    here is the pushbutton.h

    Qt Code:
    1. #ifndef PUSHBUTTON_H_
    2. #define PUSHBUTTON_H_
    3.  
    4. #include <QPushButton>
    5.  
    6. class pushbutton : public QPushButton
    7. {
    8. Q_OBJECT
    9.  
    10. public:
    11. pushbutton(const QString& text, QWidget* parent = 0) : QPushButton(text, parent)
    12. {
    13. connect(this,SIGNAL(clicked()),this,SLOT(change()));
    14. }
    15.  
    16. public slots:
    17. void change()
    18. {
    19. if(this->text() == "Don't click me!")
    20. {
    21. setText("Click me!");
    22. return;
    23. }
    24. setText("Don't click me!");
    25. }
    26. };
    27. #endif
    To copy to clipboard, switch view to plain text mode 

    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
    Qt Code:
    1. c:/document......../myproject>qmake -project
    To copy to clipboard, switch view to plain text mode 

    then i got .pro file which has following data
    Qt Code:
    1. ##Automatically generated by qmake (2.01a) Thu May 5 16:40:27 2011#####
    2.  
    3. TEMPLATE = app
    4. TARGET =
    5. DEPENDPATH += .
    6. INCLUDEPATH += .
    7.  
    8. # Input
    9. HEADERS += pushbutton.h
    10. SOURCES += main.cpp
    To copy to clipboard, switch view to plain text mode 

    but still after doing that i am getting error as
    Qt Code:
    1. obj\Debug\main.o||In function `pushbutton':|
    2. C:\Documents and Settings\t\My Documents\project\sample\pushbutton.h|11|undefined reference to `vtable for pushbutton'|
    3. C:\Documents and Settings\t\My Documents\project\sample\pushbutton.h|11|undefined reference to `vtable for pushbutton'|
    4. ||=== Build finished: 2 errors, 0 warnings ===|
    To copy to clipboard, switch view to plain text mode 

    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.

  14. #14
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default 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.

  15. #15
    Join Date
    Jun 2010
    Posts
    21
    Qt products
    Qt4
    Platforms
    Windows

    Default 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!

Similar Threads

  1. Replies: 11
    Last Post: 1st February 2018, 04:27
  2. Replies: 3
    Last Post: 12th March 2015, 20:06
  3. Replies: 4
    Last Post: 9th May 2010, 16:18
  4. Replies: 4
    Last Post: 17th February 2010, 10:52

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.