Results 1 to 4 of 4

Thread: link error LNK2001 with Q_OBJECT

  1. #1
    Join Date
    May 2009
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default link error LNK2001 with Q_OBJECT

    Hi, have a windows screensaver that I am converting to use QT.
    I made it use QSettings for the ini settings.

    I want to use QTimer and it sais I must include Q_OBJECT in the class definition for the slots to work with the timer.
    When I put Q_OBJECT, I get this link error:
    error LNK2001: unresolved external symbol "public: virtual struct QMetaObject


    Which lib do I need to include?

    I am developing the windows screensaver with visual studio 2005
    Here is my linker settings:

    /OUT:"c:\windows\SYSTEM32\STARMSG.SCR" /INCREMENTAL:NO /NOLOGO /MANIFEST /MANIFESTFILE:"c:\windows\temp\STARMSG.SCR.intermed iate.manifest" /NODEFAULTLIB:"LIBCD" /DEF:".\StarMsg.def" /PDB:".\..\Release/STARMSG.pdb" /SUBSYSTEM:WINDOWS /MACHINE:X86 /ERRORREPORT:PROMPT Qt3Support4.lib QtGui4.lib QtCore4.lib winmm.lib scrnsave.lib WSOCK32.lib Comctl32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib

    Thanks for any ideas.
    Mike
    ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~

    Moonphases screensaver

  2. #2
    Join Date
    May 2008
    Location
    Kyiv, Ukraine
    Posts
    418
    Thanks
    1
    Thanked 29 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: link error LNK2001 with Q_OBJECT

    Show us this code.

    While code is missing, the first guess is that you should run qmake after adding Q_OBJECT.
    I'm a rebel in the S.D.G.

  3. #3
    Join Date
    May 2009
    Posts
    61
    Thanks
    5
    Thanked 6 Times in 6 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: link error LNK2001 with Q_OBJECT

    I guess this is a VStudio project... ? Has the (generated) moc_-file been added to the source files?

  4. #4
    Join Date
    May 2009
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: link error LNK2001 with Q_OBJECT

    Dear lyuts and auba,
    thank you for your replies.

    yes, I have written this screensaver in visual studio and I want to gradually transfer it to QT.

    1) I could not find any moc_*.* files that I could include in the source.
    (Except of lost of files in the qt folders)
    Which one should I include in the source files?

    2) The source is this one:

    Qt Code:
    1. ////////////////////////////////////////////////////
    2. // TmioanScreenSaveAppl.h
    3.  
    4. #pragma once
    5.  
    6. #include "TmioanApplication.h"
    7. #include <QTimer.h>
    8. #include <QObject.h>
    9.  
    10.  
    11. class TmioanScreenSaveAppl: public TmioanApplication, QObject
    12. {
    13. // Q_OBJECT
    14. // With Q_OBJECT the linker gives an error
    15. // Without Q_OBJECT the timer does not work
    16.  
    17. // All classes that contain signals or slots must mention Q_OBJECT at the top of their declaration.
    18. // They must also derive (directly or indirectly) from QObject.
    19.  
    20.  
    21. private:
    22. QTimer *timer;
    23.  
    24. public:
    25. TmioanScreenSaveAppl(char *aCompanyName, char *aProductName);
    26. virtual ~TmioanScreenSaveAppl(void);
    27.  
    28. void Startup(void);
    29. void Shutdown(void);
    30.  
    31. public slots:
    32. void Advance(void);
    33.  
    34. void ConfigDialog(void);
    35. };
    36.  
    37.  
    38. ////////////////////////////////////////////////////
    39. // TmioanScreenSaveAppl.cpp
    40.  
    41. #include "TmioanScreenSaveAppl.h"
    42. #include "LogFileClass.h"
    43.  
    44.  
    45. TmioanScreenSaveAppl::TmioanScreenSaveAppl(char *aCompanyName, char *aProductName)
    46. {
    47. timer = new QTimer();
    48. connect(timer, SIGNAL(timeout()), this, SLOT(Advance()));
    49. }
    50.  
    51.  
    52. TmioanScreenSaveAppl::~TmioanScreenSaveAppl(void)
    53. {
    54. delete timer;
    55. }
    56.  
    57.  
    58. void TmioanScreenSaveAppl::Startup(void)
    59. {
    60. timer->start(50); // millisecond
    61. LogFile.add(lm_INFOLN,"TmioanScreenSaveAppl","Startup()");
    62. }
    63.  
    64.  
    65. void TmioanScreenSaveAppl::Shutdown(void)
    66. {
    67. timer->stop();
    68. }
    69.  
    70. void TmioanScreenSaveAppl::Advance(void)
    71. {
    72. LogFile.add(lm_INFOLN,"TmioanScreenSaveAppl","Advance()");
    73. }
    74.  
    75.  
    76.  
    77.  
    78. void TmioanScreenSaveAppl::ConfigDialog(void)
    79. {
    80.  
    81. }
    To copy to clipboard, switch view to plain text mode 
    ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~

    Moonphases screensaver

Similar Threads

  1. LINK : fatal error LNK1181: can't open 'delayimp.lib'
    By fcamlar in forum Installation and Deployment
    Replies: 10
    Last Post: 7th July 2006, 13:04
  2. Text Browser Link Question
    By taylor34 in forum Qt Programming
    Replies: 2
    Last Post: 20th June 2006, 19:54

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.