Results 1 to 20 of 34

Thread: make a .jpg or .bmp picture into a widget...?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2008
    Posts
    23
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    11

    Question Re: make a .jpg or .bmp picture into a widget...?

    Hi JimDaniel,
    I have tried using your example but why do I get errors like this?
    Qt Code:
    1. src\blinkingicon.cpp:4: error: new types may not be defined in a return type
    2. src\blinkingicon.cpp:4: note: (perhaps a semicolon is missing after the definition of `BlinkingIcon')
    3. src\blinkingicon.cpp:4: error: return type specification for constructor invalid
    4. src\blinkingicon.cpp:10:35: warning: unknown escape sequence '\H'
    5. mingw32-make[1]: *** [build\host\blinkingicon.o] Error 1
    6. mingw32-make: *** [release] Error 2
    To copy to clipboard, switch view to plain text mode 

    The actual code i used is exactly the same as what you have given me, only difference is just that i split it into a .h and a .cpp... like this...

    Qt Code:
    1. #ifndef __BLINKINGICON_H__
    2. #define __BLINKINGICON_H__
    3.  
    4. #include <QWidget>
    5. #include <QLabel>
    6.  
    7. class BlinkingIcon : public QWidget
    8. {
    9. Q_OBJECT
    10.  
    11. public:
    12. BlinkingIcon(QWidget * parent = 0);
    13. virtual ~BlinkingIcon();
    14.  
    15. private:
    16. QLabel * display_image;
    17. }
    18.  
    19.  
    20. #endif // __BLINKINGICON_H__
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #include "blinkingicon.h"
    2.  
    3. BlinkingIcon::BlinkingIcon(QWidget * parent)
    4. : QWidget(parent)
    5. {
    6. this->setWindowTitle(tr("My Blinking Icon"));
    7. this->resize(200, 200);
    8.  
    9. display_image = new QLabel(this);
    10. display_image->setPixmap(QPixmap("C:\HmiProject\test\nyjc.bmp"));
    11. display_image->adjustSize();
    12. }
    13.  
    14. BlinkingIcon::~BlinkingIcon(){}
    To copy to clipboard, switch view to plain text mode 

    Once again, thanks for your patient help given.

    Hi wysota,
    pardon me for my ignorance, but what does it mean by "The main difference is that a tristate QCheckBox has an indeterminate state." from the website? Is the example using an existing class QCheckBox, and giving it more functions to act as an indicator? the code... does it mean that the QCheckBox named indicator has a function indeterminateressed? I am having difficultity understanding the codes... Can you explain briefly?
    Qt Code:
    1. QCheckBox::indicator:indeterminate:pressed {
    2. image: url(:/images/checkbox_indeterminate_pressed.png);
    3. }
    To copy to clipboard, switch view to plain text mode 

    Thanks!!

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    28
    Thanked 976 Times in 912 Posts

    Default Re: make a .jpg or .bmp picture into a widget...?

    The compiler has already suggested what's wrong:
    src\blinkingicon.cpp:4: note: (perhaps a semicolon is missing after the definition of `BlinkingIcon')

  3. #3
    Join Date
    Jun 2008
    Posts
    23
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    11

    Default Re: make a .jpg or .bmp picture into a widget...?

    i actually tried putting the semicolon but the error still resides...

    and when i start another project and did the same thing, i actually get another set of errors!
    let me show u all my codes in the whole project..
    here is the main.cpp...
    Qt Code:
    1. #include <QApplication>
    2.  
    3. #include "BlinkingIcon.h"
    4.  
    5. int main(int argc, char *argv[])
    6. {
    7. QApplication app(argc, argv);
    8. BlinkingIcon picIcon;
    9. picIcon.show();
    10. return app.exec();
    11. }
    To copy to clipboard, switch view to plain text mode 

    next is the blinkingicon.h...
    Qt Code:
    1. #ifndef __BLINKINGICON_H__
    2. #define __BLINKINGICON_H__
    3.  
    4. #include <QWidget>
    5. #include <QLabel>
    6.  
    7. class BlinkingIcon : public QWidget
    8. {
    9. Q_OBJECT
    10.  
    11. public:
    12. BlinkingIcon(QWidget *parent = 0);
    13. virtual ~BlinkingIcon();
    14.  
    15. private:
    16. QLabel * display_image;
    17. }
    18.  
    19. #endif //__BLINKINGICON_H__
    To copy to clipboard, switch view to plain text mode 

    following which, is the blinkingicon.cpp...
    Qt Code:
    1. #include "BlinkingIcon.h"
    2.  
    3. BlinkingIcon::BlinkingIcon(QWidget * parent)
    4. : QWidget(parent)
    5. {
    6. this->setWindowTitle(tr("My Blinking Icon"));
    7. this->resize(200,200);
    8.  
    9. display_image = new QLabel(this);
    10. display_image->setPixmap(QPixmap("C:\HmiProject\blinkingIcon\sprites\ship\ship0000.png"));
    11. display_image->adjustSize();
    12. }
    13.  
    14. BlinkingIcon::~BlinkingIcon(){}
    To copy to clipboard, switch view to plain text mode 

    the new set of errors i am getting now is...
    Qt Code:
    1. src\main.cpp:7: error: new types may not be defined in a return type
    2. src\main.cpp:7: note: (perhaps a semicolon is missing after the definition of `BlinkingIcon')
    3. src\main.cpp:7: error: extraneous `int' ignored
    4. src\main.cpp: In function `BlinkingIcon qMain(int, char**)':
    5. src\main.cpp:11: error: invalid conversion from `int' to `QWidget*'
    6. src\main.cpp:11: error: initializing argument 1 of `BlinkingIcon::BlinkingIcon(QWidget*)'
    7. src\main.cpp: In copy constructor `BlinkingIcon::BlinkingIcon(const BlinkingIcon&)':
    8. ../../HMIDeveloper/Qt/include/QtGui/../../src/gui/kernel/qwidget.h:720: error: `QWidget::QWidget(const QWidget&)' is private
    9. src\main.cpp:11: error: within this context
    10. src\main.cpp: In function `BlinkingIcon qMain(int, char**)':
    11. src\main.cpp:11: error: initializing temporary from result of `BlinkingIcon::BlinkingIcon(QWidget*)'
    12. mingw32-make[1]: *** [build\host\main.o] Error 1
    13. mingw32-make: *** [release] Error 2
    To copy to clipboard, switch view to plain text mode 

    I don't quite get it... line 7 of main.cpp is a "{", no BlinkingIcon definition until line 9... as for line 11 i tried changing the return type to "int" type by "int(app.exec() )" but it also doesn't work. another thing i tried was to put "QWidget main(int argc, char *argv[])" or "void main(int argc, char *argv[])" instead of "int main(int argc, char *argv[])" but it doesn't help either.
    As for the other errors at line 11 (regarding qMain), I am totally lost.
    Hope you guys can enlighten me... Thanks loads!!!

  4. #4
    Join Date
    Sep 2007
    Location
    Rome, GA
    Posts
    199
    Qt products
    Qt4
    Platforms
    MacOS X Windows
    Thanks
    14
    Thanked 41 Times in 35 Posts

    Default Re: make a .jpg or .bmp picture into a widget...?

    Try putting a semi-colon after the BlinkingIcon class defintion, in your header file. I was getting compile errors with the code until I did that. Now it works fine.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: make a .jpg or .bmp picture into a widget...?

    Quote Originally Posted by mynahz View Post
    pardon me for my ignorance, but what does it mean by "The main difference is that a tristate QCheckBox has an indeterminate state." from the website?
    It means the checkbox can be checked, unchecked or "partially checked".

  6. The following user says thank you to wysota for this useful post:

    mynahz (9th June 2008)

  7. #6
    Join Date
    Jun 2008
    Posts
    23
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    11

    Default Re: make a .jpg or .bmp picture into a widget...?

    Try putting a semi-colon after the BlinkingIcon class defintion, in your header file. I was getting compile errors with the code until I did that. Now it works fine.
    Hi JimDaniel,
    Do you mind posting your code here for me to compare? because I did what you did too, but I am still stuck. I show you orig. and edited (add semicolon after BlinkingIcon) here and their error messages...
    Qt Code:
    1. #ifndef __BLINKINGICON_H__
    2. #define __BLINKINGICON_H__
    3.  
    4. #include <QWidget>
    5. #include <QLabel>
    6.  
    7. class BlinkingIcon : public QWidget
    8. {
    9. Q_OBJECT
    10.  
    11. public:
    12. BlinkingIcon(QWidget *parent = 0);
    13. virtual ~BlinkingIcon();
    14.  
    15. private:
    16. QLabel * display_image;
    17. }
    18.  
    19. #endif //__BLINKINGICON_H__
    To copy to clipboard, switch view to plain text mode 

    for this, error messages are as follows:
    src\main.cpp:7: error: new types may not be defined in a return type
    src\main.cpp:7: note: (perhaps a semicolon is missing after the definition of `BlinkingIcon')
    src\main.cpp:7: error: extraneous `int' ignored
    src\main.cpp: In function `BlinkingIcon qMain(int, char**)':
    src\main.cpp:11: error: invalid conversion from `int' to `QWidget*'
    src\main.cpp:11: error: initializing argument 1 of `BlinkingIcon::BlinkingIcon(QWidget*)'
    src\main.cpp: In copy constructor `BlinkingIcon::BlinkingIcon(const BlinkingIcon&)':
    ../../HMIDeveloper/Qt/include/QtGui/../../src/gui/kernel/qwidget.h:720: error: `QWidget::QWidget(const QWidget&)' is private
    src\main.cpp:11: error: within this context
    src\main.cpp: In function `BlinkingIcon qMain(int, char**)':
    src\main.cpp:11: error: initializing temporary from result of `BlinkingIcon::BlinkingIcon(QWidget*)'
    mingw32-make[1]: *** [build\host\main.o] Error 1
    mingw32-make: *** [release] Error 2

    for the edited version,
    Qt Code:
    1. #ifndef __BLINKINGICON_H__
    2. #define __BLINKINGICON_H__
    3.  
    4. #include <QWidget>
    5. #include <QLabel>
    6.  
    7. class BlinkingIcon :: public QWidget
    8. {
    9. Q_OBJECT
    10.  
    11. public:
    12. BlinkingIcon(QWidget *parent = 0);
    13. virtual ~BlinkingIcon();
    14.  
    15. private:
    16. QLabel * display_image;
    17. }
    18.  
    19. #endif //__BLINKINGICON_H__
    To copy to clipboard, switch view to plain text mode 

    and the error messages are...
    src\BlinkingIcon.h:7: error: expected identifier before "public"
    src\BlinkingIcon.h:7: error: expected unqualified-id before "public"
    src\main.cpp: In function `int qMain(int, char**)':
    src\main.cpp:9: error: `BlinkingIcon' was not declared in this scope
    src\main.cpp:9: error: expected `;' before "picIcon"
    src\main.cpp:10: error: `picIcon' was not declared in this scope
    src\main.cpp:9: warning: unused variable 'BlinkingIcon'
    src\main.cpp:10: warning: unused variable 'picIcon'
    mingw32-make[1]: Leaving directory `C:/HmiProject/blinkingIcon'
    mingw32-make[1]: *** [build\host\main.o] Error 1
    mingw32-make: *** [release] Error 2

  8. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    28
    Thanked 976 Times in 912 Posts

    Default Re: make a .jpg or .bmp picture into a widget...?

    Quote Originally Posted by mynahz View Post
    Do you mind posting your code here for me to compare? because I did what you did too, but I am still stuck.
    ":" is called colon, a semicolon is ";" and you are supposed to put it in line #17 of that code snippet.
    Last edited by jacek; 9th June 2008 at 19:57. Reason: typo

  9. The following user says thank you to jacek for this useful post:

    mynahz (10th June 2008)

  10. #8
    Join Date
    Sep 2007
    Location
    Rome, GA
    Posts
    199
    Qt products
    Qt4
    Platforms
    MacOS X Windows
    Thanks
    14
    Thanked 41 Times in 35 Posts

    Default Re: make a .jpg or .bmp picture into a widget...?

    Qt Code:
    1. #ifndef __BLINKINGICON_H__
    2. #define __BLINKINGICON_H__
    3.  
    4. #include <QWidget>
    5. #include <QLabel>
    6.  
    7. class BlinkingIcon : public QWidget
    8. {
    9. Q_OBJECT
    10.  
    11. public:
    12. BlinkingIcon(QWidget *parent = 0);
    13. virtual ~BlinkingIcon();
    14.  
    15. private:
    16. QLabel * display_image;
    17. };
    18.  
    19. #endif //__BLINKINGICON_H__
    To copy to clipboard, switch view to plain text mode 

  11. The following user says thank you to JimDaniel for this useful post:

    mynahz (10th June 2008)

Similar Threads

  1. Compiling with Qmake/Make
    By VireX in forum Newbie
    Replies: 25
    Last Post: 22nd February 2007, 05:57

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
  •  
Qt is a trademark of The Qt Company.