Results 1 to 5 of 5

Thread: errors

  1. #1
    Join Date
    Jun 2008
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default errors

    Alright so here is my simple code...

    header.cpp
    Qt Code:
    1. #include<QLabel>
    2. #include<QPushButton>
    3. #include<QVBoxLayout>
    4. #include<QCheckBox>
    5. #include<QLineEdit>
    6.  
    7. #include"header.h"
    8.  
    9.  
    10. widg::widg(QWidget *parent)
    11. : QWidget(parent)
    12. {
    13.  
    14. label = new QLabel(tr("Find What"));
    15. line = new QLineEdit;
    16. label->setBuddy(line);
    17.  
    18. close = new QPushButton(tr("Close"));
    19. close->resize(50,30);
    20.  
    21. find = new QPushButton(tr("Find"));
    22. find->resize(50,30);
    23. find->setEnabled(false);
    24. find->setDefault(true);
    25.  
    26. casechk = new QCheckBox(tr("Case Sensitive"));
    27. back = new QCheckBox(tr("Backward Search"));
    28.  
    29. connect(close,SIGNAL(clicked()),this,SLOT(quit()));
    30. connect(line,SIGNAL(textChanged(const QString &)),this,SLOT(enableFind(const QString &)));
    31. connect(find,SIGNAL(clicked()),this,SLOT(findClicked()));
    32.  
    33. lay->addWidget(label);
    34. lay->addWidget(line);
    35. lay->addWidget(casechk);
    36. lay->addWidget(back);
    37. lay->addWidget(find);
    38. lay->addWidget(close);
    39. setLayout(lay);
    40.  
    41. }
    42.  
    43. void widg::findClicked()
    44. {
    45. QString text = line->text();
    46.  
    47. Qt::CaseSensitivity ct = casechk->isChecked() ? Qt::CaseSensitive : Qt::CaseInsensitive;
    48.  
    49. if(back->isChecked())
    50. {
    51. emit findprev(text, ct);
    52. }
    53. else
    54. {
    55. emit findnext(text, ct);
    56. }
    57. }
    58.  
    59. void widg::enableFind(const QString &text)
    60. {
    61. find->setEnabled(true);
    62. }
    To copy to clipboard, switch view to plain text mode 

    the header file

    Qt Code:
    1. #ifndef HEADER_H
    2. #define HEADER_H
    3.  
    4. #include<QWidget>
    5.  
    6. class QLabel;
    7. class QLineEdit;
    8. class QCheckBox;
    9.  
    10. class widg:public QWidget
    11. {
    12.  
    13. public:
    14.  
    15. widg(QWidget *parent = 0);
    16.  
    17. private slots:
    18.  
    19. void findClicked();
    20. void enableFind(const QString &text);
    21.  
    22. signals:
    23.  
    24. void findnext(const QString &str, Qt::CaseSensitivity cs);
    25. void findprev(const QString &str, Qt::CaseSensitivity cs);
    26.  
    27. private:
    28.  
    29. QLabel *label;
    30. QLineEdit *line;
    31. QPushButton *find;
    32. QPushButton *close;
    33. QCheckBox *casechk;
    34. QCheckBox *back;
    35. };
    36.  
    37. #endif
    To copy to clipboard, switch view to plain text mode 

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

    and i get the following error message
    Linking...
    header.obj : error LNK2001: unresolved external symbol "protected: void __thiscall widg::findnext(class QString const &,enum Qt::CaseSensitivity)" (?findnext@widg@@IAEXABVQString@@W4CaseSensitivity @Qt@@@Z)
    header.obj : error LNK2001: unresolved external symbol "protected: void __thiscall widg::findprev(class QString const &,enum Qt::CaseSensitivity)" (?findprev@widg@@IAEXABVQString@@W4CaseSensitivity @Qt@@@Z)
    release/r4.exe : fatal error LNK1120: 2 unresolved externals
    Error executing link.exe.

    r4.exe - 3 error(s), 0 warning(s)
    i don't know what to do..!! please help...!!
    Last edited by jpn; 14th June 2008 at 19:55. Reason: changed [quote] to [code] tags

  2. #2
    Join Date
    Sep 2007
    Location
    Rome, GA
    Posts
    199
    Thanks
    14
    Thanked 41 Times in 35 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: errors

    Just add Q_OBJECT macro to your header file and it will compile.

    Qt Code:
    1. #ifndef HEADER_H
    2. #define HEADER_H
    3.  
    4. #include<QWidget>
    5.  
    6. class QLabel;
    7. class QLineEdit;
    8. class QCheckBox;
    9.  
    10. class widg:public QWidget
    11. {
    12. Q_OBJECT
    13.  
    14. public:
    15.  
    16. widg(QWidget *parent = 0);
    17.  
    18. private slots:
    19.  
    20. void findClicked();
    21. void enableFind(const QString &text);
    22.  
    23. signals:
    24.  
    25. void findnext(const QString &str, Qt::CaseSensitivity cs);
    26. void findprev(const QString &str, Qt::CaseSensitivity cs);
    27.  
    28. private:
    29.  
    30. QLabel *label;
    31. QLineEdit *line;
    32. QPushButton *close;
    33. QCheckBox *casechk;
    34. QCheckBox *back;
    35. };
    36.  
    37. #endif
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jun 2008
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default

    ok...I tried putting Q_OBJECT in my header file...now i am getting 6 errors...

    --------------------Configuration: r1 - Win32 Release--------------------
    Running MOC on ..\..\..\test5\header.h
    Compiling...
    moc_header.cpp
    Linking...
    main.obj : error LNK2001: unresolved external symbol "public: void __thiscall widg::setval2(int)" (?setval2@widg@@QAEXH@Z)
    main.obj : error LNK2001: unresolved external symbol "public: void __thiscall widg::setval1(int)" (?setval1@widg@@QAEXH@Z)
    main.obj : error LNK2001: unresolved external symbol "public: __thiscall cannonfld::cannonfld(class QWidget *)" (??0cannonfld@@QAE@PAVQWidget@@@Z)
    main.obj : error LNK2001: unresolved external symbol "public: void __thiscall widg::setrng2(int,int)" (?setrng2@widg@@QAEXHH@Z)
    main.obj : error LNK2001: unresolved external symbol "public: void __thiscall widg::setrng1(int,int)" (?setrng1@widg@@QAEXHH@Z)
    release/r1.exe : fatal error LNK1120: 5 unresolved externals
    Error executing link.exe.

    r1.exe - 6 error(s), 0 warning(s)
    what i want to knw is why is it displaying errors in the functions which don't exist anywhere in my code...??


    main.obj : error LNK2001: unresolved external symbol "public: void __thiscall widg::setval2(int)" (?setval2@widg@@QAEXH@Z)
    main.obj : error LNK2001: unresolved external symbol "public: void __thiscall widg::setval1(int)" (?setval1@widg@@QAEXH@Z)
    main.obj : error LNK2001: unresolved external symbol "public: __thiscall cannonfld::cannonfld(class QWidget *)" (??0cannonfld@@QAE@PAVQWidget@@@Z)
    main.obj : error LNK2001: unresolved external symbol "public: void __thiscall widg::setrng2(int,int)" (?setrng2@widg@@QAEXHH@Z)
    main.obj : error LNK2001: unresolved external symbol "public: void __thiscall widg::setrng1(int,int)" (?setrng1@widg@@QAEXHH@Z)
    release/r1.exe : fatal error LNK1120: 5 unresolved externals
    Error executing link.exe.

    r1.exe - 6 error(s), 0 warning(s)
    Last edited by wysota; 15th June 2008 at 06:28.

  4. #4
    Join Date
    Sep 2007
    Location
    Rome, GA
    Posts
    199
    Thanks
    14
    Thanked 41 Times in 35 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: errors

    I'm not sure. Are these functions you had in there but took out? If so, assuming you're using Visual Studio, go to Build->Clean Solution, then Build->Rebuild Solution. See if that helps.

  5. #5
    Join Date
    Jun 2008
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: errors

    ahhh...!!! got it.... thanks mate.... it worked...

Similar Threads

  1. Errors in building qtopia2.2
    By namita in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 5th June 2008, 07:57
  2. Ui class errors
    By calef13 in forum Qt Programming
    Replies: 2
    Last Post: 4th November 2007, 13:53
  3. Qt 4.1.0 - static examples run with errors!
    By Elder Orb in forum Qt Programming
    Replies: 1
    Last Post: 12th January 2006, 09: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.