Results 1 to 17 of 17

Thread: Expected class-name before '{' token

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Expected class-name before '{' token

    add #include <QWidget> in this file, e.g.
    Qt Code:
    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3.  
    4. #include <QWidget>
    5. #include "ui_mainwindow.h"
    6. ...
    To copy to clipboard, switch view to plain text mode 
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  2. #2
    Join Date
    Jun 2009
    Posts
    6
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: Expected class-name before '{' token

    Tried it, same result.

  3. #3
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Expected class-name before '{' token

    attach all sources.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  4. #4
    Join Date
    Jun 2009
    Posts
    6
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: Expected class-name before '{' token

    Attached #include <QWidget> too all other files main.cpp, mainwindow.cpp, and mainwindow.h. I think that is what you wanted me to try. Still get the same error message.

  5. #5
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Expected class-name before '{' token

    no, I was asking you to upload your sources, that I can try to compile your project by myself.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  6. #6
    Join Date
    Jun 2009
    Posts
    6
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: Expected class-name before '{' token

    Sorry. Here we go...

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

    mainwindow.cpp
    Qt Code:
    1. #include "mainwindow.h"
    2. #include <QtGui>
    3. #include <QPixmap>
    4.  
    5.  
    6. MainWindow::MainWindow(QWidget *parent)
    7. {
    8. setupUi(this);
    9. connect( pushButton_display, SIGNAL( clicked() ), this, SLOT( display_pic() ) );
    10.  
    11. }
    12.  
    13. void MainWindow::display_pic()
    14. {
    15. QPixmap pixmap("Dima.jpg");
    16.  
    17. label_image->setPixmap(pixmap);
    18. }
    To copy to clipboard, switch view to plain text mode 

    mainwindow.h
    Qt Code:
    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3.  
    4. #include <QWidget>
    5. #include "ui_mainwindow.h"
    6.  
    7.  
    8. class MainWindow : public QWidget, private Ui::MainWindowDLG
    9. {
    10. Q_OBJECT
    11.  
    12. public:
    13. MainWindow(QWidget *parent = 0);
    14.  
    15. public slots:
    16. void display_pic();
    17.  
    18. };
    19.  
    20. #endif
    To copy to clipboard, switch view to plain text mode 

    ui_mainwindow.h
    Qt Code:
    1. /********************************************************************************
    2. ** Form generated from reading ui file 'mainwindow.ui'
    3. **
    4. ** Created: Mon Jun 15 22:04:49 2009
    5. ** by: Qt User Interface Compiler version 4.5.1
    6. **
    7. ** WARNING! All changes made in this file will be lost when recompiling ui file!
    8. ********************************************************************************/
    9.  
    10. #ifndef UI_MAINWINDOW_H
    11. #define UI_MAINWINDOW_H
    12.  
    13. #include <QtCore/QVariant>
    14. #include <QtGui/QAction>
    15. #include <QtGui/QApplication>
    16. #include <QtGui/QButtonGroup>
    17. #include <QtGui/QHeaderView>
    18. #include <QtGui/QLabel>
    19. #include <QtGui/QMainWindow>
    20. #include <QtGui/QPushButton>
    21. #include <QtGui/QWidget>
    22.  
    23. QT_BEGIN_NAMESPACE
    24.  
    25. class Ui_MainWindow
    26. {
    27. public:
    28. QWidget *centralWidget;
    29. QLabel *label_image;
    30. QPushButton *pushButton_display;
    31.  
    32. void setupUi(QMainWindow *MainWindow)
    33. {
    34. if (MainWindow->objectName().isEmpty())
    35. MainWindow->setObjectName(QString::fromUtf8("MainWindow"));
    36. MainWindow->resize(770, 524);
    37. MainWindow->setStyleSheet(QString::fromUtf8("background-color: rgb(136, 162, 255);\n"
    38. ""));
    39. centralWidget = new QWidget(MainWindow);
    40. centralWidget->setObjectName(QString::fromUtf8("centralWidget"));
    41. label_image = new QLabel(centralWidget);
    42. label_image->setObjectName(QString::fromUtf8("label_image"));
    43. label_image->setGeometry(QRect(10, 10, 751, 461));
    44. label_image->setStyleSheet(QString::fromUtf8("background-color: rgba(62, 99, 255, 43);"));
    45. pushButton_display = new QPushButton(centralWidget);
    46. pushButton_display->setObjectName(QString::fromUtf8("pushButton_display"));
    47. pushButton_display->setGeometry(QRect(330, 480, 113, 32));
    48. MainWindow->setCentralWidget(centralWidget);
    49.  
    50. retranslateUi(MainWindow);
    51.  
    52. QMetaObject::connectSlotsByName(MainWindow);
    53. } // setupUi
    54.  
    55. void retranslateUi(QMainWindow *MainWindow)
    56. {
    57. MainWindow->setWindowTitle(QApplication::translate("MainWindow", "MainWindow", 0, QApplication::UnicodeUTF8));
    58. label_image->setText(QString());
    59. pushButton_display->setText(QApplication::translate("MainWindow", "Push Me", 0, QApplication::UnicodeUTF8));
    60. Q_UNUSED(MainWindow);
    61. } // retranslateUi
    62.  
    63. };
    64.  
    65. namespace Ui {
    66. class MainWindow: public Ui_MainWindow {};
    67. } // namespace Ui
    68.  
    69. QT_END_NAMESPACE
    70.  
    71. #endif // UI_MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 

  7. #7
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Expected class-name before '{' token

    try this

    mainwindow.cpp
    Qt Code:
    1. #include "mainwindow.h"
    2. #include <QtGui>
    3. #include <QPixmap>
    4.  
    5.  
    6. MainWindow::MainWindow(QWidget *parent)
    7. : QMainWindow(this)
    8. {
    9. setupUi(this);
    10. connect( pushButton_display, SIGNAL( clicked() ), this, SLOT( display_pic() ) );
    11.  
    12. }
    13.  
    14. void MainWindow::display_pic()
    15. {
    16. QPixmap pixmap("Dima.jpg");
    17.  
    18. label_image->setPixmap(pixmap);
    19. }
    To copy to clipboard, switch view to plain text mode 

    mainwindow.h
    Qt Code:
    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3.  
    4. #include <QMainWindow>
    5. #include "ui_mainwindow.h"
    6.  
    7.  
    8. class MainWindow : public QMainWindow, private Ui::MainWindowDLG
    9. {
    10. Q_OBJECT
    11.  
    12. public:
    13. MainWindow(QWidget *parent = 0);
    14.  
    15. public slots:
    16. void display_pic();
    17.  
    18. };
    19.  
    20. #endif
    To copy to clipboard, switch view to plain text mode 
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  8. #8
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Expected class-name before '{' token

    Quote Originally Posted by spirit View Post
    Qt Code:
    1. MainWindow::MainWindow(QWidget *parent)
    2. : QMainWindow(this)
    To copy to clipboard, switch view to plain text mode 
    Hi, a short side question. I pass everytime parent to the ctor of the base class. What's the advantage of passing this?

  9. #9
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Expected class-name before '{' token

    mistyped, of course must be passed parent.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  10. #10
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Expected class-name before '{' token

    Quote Originally Posted by spirit View Post
    mistyped, of course must be passed parent.
    Fine, than I can stop thinking about

  11. #11
    Join Date
    Jun 2009
    Posts
    6
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: Expected class-name before '{' token

    Still not working.

  12. #12
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Expected class-name before '{' token

    ok, attach to your next post an archive with sources, pro-file and ui-file.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

Similar Threads

  1. Replies: 3
    Last Post: 10th November 2008, 16:14
  2. Using flex with Qt4
    By xgoan in forum Qt Programming
    Replies: 4
    Last Post: 24th October 2008, 15:21
  3. expected initializer before »)« token
    By Holy in forum Qt Programming
    Replies: 2
    Last Post: 24th May 2008, 16:24
  4. Need help integrating sigc++ with a KDE3/Qt3 app
    By Valheru in forum Qt Programming
    Replies: 1
    Last Post: 17th November 2007, 15:39
  5. Compile Errors
    By luffy27 in forum Qt Programming
    Replies: 3
    Last Post: 4th November 2006, 05:26

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.