Results 1 to 11 of 11

Thread: What is wrong with this simple example ?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2007
    Posts
    30
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5 PyQt3 PyQt4
    Platforms
    MacOS X

    Question What is wrong with this simple example ?

    It should work (I think)



    Qt Code:
    1. #include <QApplication>
    2. #include <QFont>
    3. #include <QPushButton>
    4. #include <QWidget>
    5. #include <QCalendarWidget>
    6. #include <QVBoxLayout>
    7. #include <iostream>
    8.  
    9. class MyWidget : public QWidget
    10. {
    11. Q_OBJECT
    12.  
    13. public:
    14. MyWidget(QWidget *parent = 0) ;
    15.  
    16. public slots:
    17. void calClicked ( const QDate & ) ;
    18. } ;
    19.  
    20. void MyWidget::calClicked ( const QDate & theDate )
    21. { std::cout << theDate.toString( "ddd MMMM d yyyy" ).toStdString() << std::endl ;
    22. }
    23.  
    24. MyWidget::MyWidget ( QWidget *parent ) : QWidget ( parent )
    25. {
    26. QPushButton *quit = new QPushButton ( tr ( "Quit" ), this ) ;
    27. quit->setGeometry ( 62, 40, 75, 30 ) ;
    28. quit->setFont ( QFont( "Times", 18, QFont::Bold ) ) ;
    29. connect ( quit, SIGNAL( clicked() ), qApp, SLOT(quit()) ) ;
    30.  
    31. QCalendarWidget *dateEdit = new QCalendarWidget () ;
    32. connect ( dateEdit, SIGNAL( clicked(const QDate&) ), this, SLOT(calClicked(const QDate&)) ) ;
    33.  
    34. QVBoxLayout *layout = new QVBoxLayout;
    35. layout->addWidget(dateEdit);
    36. layout->addWidget(quit);
    37. setLayout(layout);
    38.  
    39. }
    40.  
    41. int main(int argc, char* argv[] )
    42. {
    43. QApplication app(argc, argv ) ;
    44. MyWidget widget ;
    45. widget.show() ;
    46. return app.exec() ;
    47. }
    To copy to clipboard, switch view to plain text mode 

    Here's the compile:
    c++ -headerpad_max_install_names -o DIY-Cal.app/Contents/MacOS/DIY-Cal main.o -L/usr/local/Trolltech/Qt-4.2.2/lib -lQtGui -L/Volumes/Whopper07/TiBookPurge/qt-mac-opensource-src-4.2.2/lib -framework Carbon -framework QuickTime -framework AppKit -lQtCore -lz -lm -liconv -framework ApplicationServices
    /usr/bin/ld: Undefined symbols:
    MyWidget::staticMetaObject
    vtable for MyWidget
    collect2: ld returned 1 exit status
    make: *** [DIY-Cal.app/Contents/MacOS/DIY-Cal] Error 1
    What is even weirder, it WILL compile if I remove "Q_OBJECT", but when I run it, it says:
    Object::connect: No such slot QWidget::calClicked(QDate)
    Help !
    Last edited by jacek; 16th January 2007 at 11:23. Reason: changed [code] to [quote]

Similar Threads

  1. Simple way to expand all nodes on a QTreeView?
    By cboles in forum Qt Programming
    Replies: 10
    Last Post: 12th April 2014, 16:54
  2. QTextEdit simple question
    By Marcopolo in forum Qt Tools
    Replies: 4
    Last Post: 11th October 2007, 00:01
  3. Release my simple program to other users ?
    By probine in forum Qt Programming
    Replies: 9
    Last Post: 9th July 2006, 23:42
  4. QListWidget...what's wrong
    By nupul in forum Newbie
    Replies: 16
    Last Post: 4th April 2006, 12:17
  5. can't get a simple dialog working
    By pthomas in forum Newbie
    Replies: 8
    Last Post: 13th January 2006, 14: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.