Results 1 to 11 of 11

Thread: What is wrong with this simple example ?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Kerala
    Posts
    371
    Thanks
    76
    Thanked 37 Times in 32 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: What is wrong with this simple example ?

    Quote Originally Posted by aamer4yu View Post
    I dont think thats the case...
    and I even dont think this is a simple example...
    I tried the code too, (VC++ 6.0 )but it is giving the following errors :
    I think you shouldn't think too much, and just try out the solution mentioned

    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. }
    48.  
    49. #include "main.moc"
    To copy to clipboard, switch view to plain text mode 


    Try this code out It should compile
    We can't solve problems by using the same kind of thinking we used when we created them

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: What is wrong with this simple example ?

    ok I am not thinking much now..
    can u tell more ? how does moc work ?
    if main.moc was not included, main_moc.cpp might have been generated ? hope I am right... are there any other files generated ??

    how do one choose to what to include? ?

  3. #3
    Join Date
    Jan 2006
    Location
    Bremen, Germany
    Posts
    554
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: What is wrong with this simple example ?

    As you can moc can work on a source and on a header file. For a beginner it's imo better to just use the header-file approach.
    moc on src file creates a <filename>.moc which has to be included in <filename>.cpp
    moc on header file creates moc_<filename>.cpp which is automagically added to the sourcefile-list by qmake.

    Be aware that cmake & automake use a different naming sheme (and you have to include moc src and moc header - it's not done by the buildsystem there)

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

    Default Re: What is wrong with this simple example ?

    Thanks. That did it .

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.