Results 1 to 15 of 15

Thread: connect() problem

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2010
    Posts
    62
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    3

    Default Re: connect() problem

    I've changed the code and now it works!
    Qt Code:
    1. QPushButton *NewButton= new QPushButton(this);
    2. NewButton->setText("Button");
    3.  
    4. actionsObj *ao= new actionsObj;
    5. connect(NewButton, SIGNAL(clicked()),ao, SLOT(ButtonClicked()));
    6. NewButton->setGeometry(50, 40, 300, 200);
    7. NewButton->show();
    8. //ui->setupUi(this);
    To copy to clipboard, switch view to plain text mode 

    the only problem now is that if I uncomment the last row the button isn't clickable anymore. What could be the problem?

  2. #2
    Join Date
    Aug 2010
    Posts
    62
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    3

    Default Re: connect() problem

    ok, I've done it!
    simply, the ui->setupUi(this); row is to be written before the other rows, not in the bottom
    thanks you all

  3. #3
    Join Date
    Aug 2010
    Posts
    62
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    3

    Default Re: connect() problem

    here I am again for the same problem...
    mainwindow.cpp:
    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3. #include <QObject>
    4.  
    5. class act :public QObject
    6. {
    7. Q_OBJECT
    8.  
    9. };
    10.  
    11. MainWindow::MainWindow(QWidget *parent) :
    12. QMainWindow(parent),
    13. ui(new Ui::MainWindow)
    14. {
    15. ui->setupUi(this);
    16.  
    17. act *ao= new act;
    18. }
    19.  
    20. MainWindow::~MainWindow()
    21. {
    22. delete ui;
    23. }
    To copy to clipboard, switch view to plain text mode 

    this little code returns me the same error:
    collect2: Id returned 1 exit status
    what it refers to??
    in addition if I comment the Q_OBJECT line it compiles without errors!
    Last edited by harmodrew; 5th August 2010 at 16:16.

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

    Default Re: connect() problem

    put your class act in a single file or make sure moc runing right for your class. Simpliest is every class a single file!

  5. The following user says thank you to Lykurg for this useful post:

    harmodrew (5th August 2010)

  6. #5
    Join Date
    Aug 2010
    Posts
    62
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    3

    Default Re: connect() problem

    thanks for the reply, it helped! but, why are we obliged to write the class in an another file to make it work? what does it change?

  7. #6
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    6
    Thanked 348 Times in 333 Posts

    Default Re: connect() problem

    Its to do with the meta object compiler. You can have classes in the same file as your .cpp if you want, but if they include the Q_OBJECT macro, then you need to run MOC, so ideally those classes should be in .h files instead.

  8. #7
    Join Date
    Aug 2010
    Posts
    62
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    3

    Default Re: connect() problem

    oh, it's clear now! thank again!

Similar Threads

  1. PyQT connect problem
    By di_zou in forum Newbie
    Replies: 1
    Last Post: 6th November 2009, 18:03
  2. Connect Problem
    By nrabara in forum Newbie
    Replies: 3
    Last Post: 4th May 2009, 13:19
  3. connect problem
    By liengen in forum Newbie
    Replies: 2
    Last Post: 22nd October 2008, 17:21
  4. Problem with connect()
    By mrnor3 in forum Qt Programming
    Replies: 3
    Last Post: 23rd July 2008, 15:05
  5. connect problem QDialog
    By Zergi in forum Newbie
    Replies: 1
    Last Post: 1st January 2008, 14:36

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.