Results 1 to 4 of 4

Thread: Can't compile programs in Visual Studio.net 2005

  1. #1
    Join Date
    Jul 2006
    Posts
    126
    Thanks
    17
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Can't compile programs in Visual Studio.net 2005

    Warning 1 warning LNK4098: defaultlib 'libcmt.lib' conflicts with use of other libs; use /NODEFAULTLIB:library MSVCRT.lib
    Error 2 error LNK2019: unresolved external symbol "public: static struct QMetaObject const BotonesDialogo::staticMetaObject" (?staticMetaObject@BotonesDialogo@@2UQMetaObject@@ B) referenced in function "public: static class QString __cdecl BotonesDialogo::tr(char const *,char const *)" (?tr@BotonesDialogo@@SA?AVQString@@PBD0@Z) BotonesDialogo.obj
    Error 3 error LNK2019: unresolved external symbol "protected: void __thiscall BotonesDialogo::accepted(void)" (?accepted@BotonesDialogo@@IAEXXZ) referenced in function "public: void __thiscall BotonesDialogo::accept(void)" (?accept@BotonesDialogo@@QAEXXZ) BotonesDialogo.obj
    Error 4 error LNK2019: unresolved external symbol "protected: void __thiscall BotonesDialogo::canceled(void)" (?canceled@BotonesDialogo@@IAEXXZ) referenced in function "public: void __thiscall BotonesDialogo::cancel(void)" (?cancel@BotonesDialogo@@QAEXXZ) BotonesDialogo.obj
    Error 5 error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall BotonesDialogo::metaObject(void)const " (?metaObject@BotonesDialogo@@UBEPBUQMetaObject@@XZ ) BotonesDialogo.obj
    Error 6 error LNK2001: unresolved external symbol "public: virtual void * __thiscall BotonesDialogo::qt_metacast(char const *)" (?qt_metacast@BotonesDialogo@@UAEPAXPBD@Z) BotonesDialogo.obj
    Error 7 error LNK2001: unresolved external symbol "public: virtual int __thiscall BotonesDialogo::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@BotonesDialogo@@UAEHW4Call@QMetaObje ct@@HPAPAX@Z) BotonesDialogo.obj
    Error 8 fatal error LNK1120: 6 unresolved externals c:\Chus\QT\Widgets\BotonesDialogo\release\BotonesD ialogo.exe 1
    It occours only when I try to use 'emit' word, thanks

    The code:

    BotonesDialogo.cpp:
    Qt Code:
    1. #include "BotonesDialogo.h"
    2.  
    3. #include <QHBoxLayout>
    4. #include <QPushButton>
    5.  
    6. BotonesDialogo::BotonesDialogo(QWidget *parent):QWidget(parent){
    7. QPushButton *accept=new QPushButton;
    8. accept->setText(tr("&Aceptar"));
    9. QPushButton *cancel=new QPushButton;
    10. cancel->setText(tr("&Cancelar"));
    11.  
    12. connect(accept,SIGNAL(clicked()),this,SLOT(accept()));
    13. connect(cancel,SIGNAL(clicked()),this,SLOT(cancel()));
    14.  
    15. QHBoxLayout *hLayout=new QHBoxLayout;
    16. hLayout->setAlignment(Qt::AlignRight | Qt::AlignBottom);
    17. hLayout->addWidget(accept);
    18. hLayout->addWidget(cancel);
    19. setLayout(hLayout);
    20. }
    21.  
    22. void BotonesDialogo::accept(){
    23. emit accepted();
    24. }
    25.  
    26. void BotonesDialogo::cancel(){
    27. emit canceled();
    28. }
    To copy to clipboard, switch view to plain text mode 

    BotonesDialogo.h:
    Qt Code:
    1. #ifndef __BOTONESDIALOGO_H_
    2. #define __BOTONESDIALOGO_H_
    3.  
    4. #include <QWidget>
    5.  
    6. class BotonesDialogo:public QWidget{
    7. Q_OBJECT
    8.  
    9. public:
    10. BotonesDialogo(QWidget *parent=0);
    11. public slots:
    12. void accept();
    13. void cancel();
    14. signals:
    15. void accepted();
    16. void canceled();
    17. };
    18.  
    19. #endif
    To copy to clipboard, switch view to plain text mode 

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

    Thank's

  2. #2
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Can't compile programs in Visual Studio.net 2005

    The problem is because both your button names and the slot names are same.

    accept,accept()
    cancel,cancel()

    Also, you will have memory leak since the buttons will not be deleted.

    You should have something like

    Qt Code:
    1. QPushButton *acceptButton = new QPushButton(tr("yourText"),this);
    2. connect(accpetButton,SIGNAL(clicked()),this,SLOT(accept()));
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to munna for this useful post:

    xgoan (7th July 2006)

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

    Default Re: Can't compile programs in Visual Studio.net 2005

    Quote Originally Posted by xgoan
    It occours only when I try to use 'emit' word
    Did you run moc program on your sources to generate signals & slots implementation? If you use qmake, you must re-run it to generate a new Makefile every time you add a Q_OBJECT macro.

    Quote Originally Posted by munna
    The problem is because both your button names and the slot names are same.

    accept,accept()
    cancel,cancel()
    That shouldn't be a problem in this case, since SLOT and SIGNAL macros convert their parameter to strings.

    Quote Originally Posted by munna
    Also, you will have memory leak since the buttons will not be deleted.
    Right, those buttons should have a parent.

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

    xgoan (7th July 2006)

  6. #4
    Join Date
    Jul 2006
    Posts
    126
    Thanks
    17
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Can't compile programs in Visual Studio.net 2005

    Ouch. hehe. I will try it.

    I'm just learning Qt now.

    Thank you

Similar Threads

  1. Qt 4.1.0 on Visual Studio 2005
    By nErnie in forum Installation and Deployment
    Replies: 8
    Last Post: 6th July 2006, 01:56
  2. Qt Designer & Visual Studio 2005
    By pSiCho in forum Qt Tools
    Replies: 6
    Last Post: 9th February 2006, 14:40

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.