November 17, 2011

feedmeqt feedmeqt
Lab Rat
34 posts

Parse error when declaring under public slot but not under public!!!

 

Hi,

For past 3 days I’ve been working with COM object and faced few problems which got cleared her. Hope for this I’ll be having a work around. Below are the steps which was followed; <windows7, vs2010,qt4.7.4)

1) COM project created by selecting the QT project type (Active Qt Server)

2) I removed all the UI components and derived from QObject (When I’m deriving from QWidget, I can’t call from a console application).

3) Registering through vs2010 was not possible, But registered through cmd-line successfully.

ex: cmd-line steps,

$(QTDIR)\bin\idc.exe “$(TargetPath)” /idl “$(IntDir)/Myclass.idl” -version 1.0.0
midl “$(IntDir)/Myclass.idl” /tlb “$(IntDir)/Myclass.tlb”
$(QTDIR)\bin\idc.exe “$(TargetPath)” /tlb “$(IntDir)/Myclass.tlb”
$(QTDIR)\bin\idc.exe “$(TargetPath)” /regserver

4) Now I’ll present some pseudo-code and will describe about the problem.

I’ve a 3rd party virtual class ,

  1. thirdParty.h
  2.  
  3.     thirdParty: public IUnknown
  4.     {
  5.     public:
  6.         virtual /* [helpstring] */ HRESULT STDMETHODCALLTYPE Init(
  7.             /* [out][in] */ LPTNTDRVINFO pDrvInfo) = 0;
  8.  
  9.  
  10.          /// some more...
  11.     };
  12.  
  13.  
  14. Myclass.h  // interface
  15.  
  16.  
  17. #include <ActiveQt/QAxBindable>
  18.  
  19. #include "Myclass_global.h"
  20.  
  21. #include "IEC61850ErrorCodes.h"
  22. #include <qobject.h>
  23.  
  24. class MYCLASS_EXPORT IEC61850DriverClass : public QObject, public QAxBindable , public thirdParty
  25. {
  26.  
  27.  Q_OBJECT
  28. public:
  29.  IEC61850DriverClass( QObject *p = 0);
  30.  
  31.  // STDMETHOD(method) , will refer some windows specific file and boils down to ( __declspec(nothrow)  long __stdcall method  ) // ObjBase.h
  32.          STDMETHOD(Init) ( LPTNTDRVINFO  pDrvInfo);   /// No compilation error coming when its added here.I don't want here but need to be there in "public slot"
  33.   ///SOME MORE...
  34.  
  35.  ULONG STDMETHODCALLTYPE AddRef( void);
  36.  
  37.  ULONG STDMETHODCALLTYPE Release( void);
  38.  
  39.  STDMETHOD(QueryInterface)(
  40.                 /* [in] */ REFIID riid,
  41.                 /* [iid_is][out] */ __RPC__deref_out void __RPC_FAR *__RPC_FAR *ppvObject);
  42.  
  43. public slots:
  44.  
  45.  QString getdata(); // Only this method we can see as exposed from COM( through C# noticed)
  46.  
  47. * //But, my actual requirement is putting "Init()" here, which resulting in parse erro. No idea how to solve it.*
  48.  STDMETHOD(Init) ( LPTNTDRVINFO  pDrvInfo);  //[eg: long Initialize(  LPTNTDRVINFO   pdata),Inside which I'll be calling Init( LPTNTDRVINFO  p),but no success]
  49. private:
  50.  
  51.  QString  data;
  52. };
  53.  
  54.  
  55. Myclass.cpp // implementation
  56.  
  57.  
  58. #include "stdafx.h"
  59. #include "maptagtableclass.h"
  60. #include "Myclass.h"
  61. #include <ActiveQt/QAxFactory>
  62.  
  63.  
  64. STDMETHODIMP IEC61850DriverClass::Init(LPTNTDRVINFO pDrvInfo) {
  65.  
  66.  return OLE_E_NOCONNECTION;
  67.  
  68. }
  69.  
  70. // some code....
  71.  
  72. stdafx.h // contains all the declarations.
  73.  
  74. #include "logger.h"
  75. #include <tchar.h>
  76. #include "..\Include\Drv\thirdPart.h"   // declarations like "LPTNTDRVINFO   etc" ..
  77. #include "..\Include\ApmsUtilityInt.h"

So, Is that namespace for QT is causing this issue or is that public slot require special convention for complex declaration ? Since its compilation error, I played with ordering the header file but still no result :(.

10 replies

November 17, 2011

Volker Volker
Ant Farmer
5428 posts

It would be helpful if you told us the actual error message.

November 18, 2011

feedmeqt feedmeqt
Lab Rat
34 posts

Ok, this is the error,

C:\MyClass.h(48): Parse error at “)” Moc’ing MyClass.h… C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppCommon.targets(151,5): error MSB6006: “cmd.exe” exited with code 1. ====== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ======

November 18, 2011

feedmeqt feedmeqt
Lab Rat
34 posts

After doing further analysis I’ve reached to some what specific issue with QT framework.

MyClass.h

  1. // Refer above ...
  2. LineNo:48  STDMETHOD(Init) ( LPTNTDRVINFO  pDrvInfo); // earlier ..
  3.  
  4. LineNo:48  QString intialize ( LPTNTDRVINFO  pDrvInfo); // Final one.. Compilation no error, for registering obviously through cmd-line was able to register COM Dll.

No, I can’t see the initialize() function exposed? No idea what is the problem.

November 18, 2011

feedmeqt feedmeqt
Lab Rat
34 posts

Hi,

LPTNTDRVINFO , is a structure type, declation in this form ,

  1. typedef struct {
  2.  
  3. // bla bla
  4.  
  5. }DRVINGO, *LPTNTDRVINFO;

November 18, 2011

Volker Volker
Ant Farmer
5428 posts

STDMETHOD (Init) seems to be some kind of macro or the like. To my knowledge, moc does not use the C/C++ preprocessor prior to its own parsing. Which means that it cannot parse that line, as it is no standard “simple” method prototype.

What do you mean with “I can’t see the initialize() function exposed”?

Additionally, it may be necessary that you will have to register the LPTNTDRVINFO as a type in the Qt meta type system, see qRegisterMetaType [doc.qt.nokia.com] docs for details.

November 20, 2011

feedmeqt feedmeqt
Lab Rat
34 posts

Hi,

Sorry for not replying soon. Due to the problem mentioned above I was engaged in writing a new plain C++ COM object(New to C++, Read a lot and implemented.) which will be a wrapper class for QT.So, its working fine.

“What do you mean with “I can’t see the initialize() function exposed”?”
Yes, Your correct due to lack of experience in C++, I’m not familiar with the terms used in C++, will be improved in coming days.

What I meant is in the generated *idl file , its mentioned as un-supported type.

  1. Line 45: QString getdata();
  2. LineNo:48  QString intialize ( LPTNTDRVINFO  pDrvInfo); // LPTNTDRVINFO, un-supported type.
  3.  

Due to this , the class which calls my COM object can only see getdata(), means unable to call initialize(). So, *qRegisterMetaType * will solve this requirement ? Need your thoughts!!!

November 20, 2011

Volker Volker
Ant Farmer
5428 posts

Sorry, I never got my hands dirty with COM objects and IDL files, I can only speak of Qt design principles in general. So, to use custom data types in signals/slots you need to call qRegisterMetatype. I don’t know whether that works – I suggest just trying it out.

And regardig that STDMETHOD problem, from a quick search on google, I’d say it’s a macro – and moc seems not to support this notation.

As a workaround, you might just add your STDMETHOD in the public section, and add an additional standard public slot that calls the other method as implementation (or the other way round, that’s up to you).

November 21, 2011

Gerolf Gerolf
Hobby Entomologist
3287 posts

Hi,

As a side note: STDMETHOD declares a method as:

  1. HRESULT __stdcall foo();

I’m pretty sure, moc can’t understand these macros, especially, as the C pre proc is not running before moc is run.

The Qt ActiveX stuff exports signals and slots out of the meta object description. All data types that can be put to a QVariant can be used as parameters. If you define custom types, you must use qRegisterMetaType to add the type to the meta info. Then it should be possible to use it.

By the way, in your OP, you had Init 2 times defined. one time as COM method and one time as slot.

 Signature 

Nokia Certified Qt Specialist.
Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

November 22, 2011

feedmeqt feedmeqt
Lab Rat
34 posts

No, I just wanted to show that, declaring under slots gave me error(as you said , moc runs ) and the same declaring under public donot throw error.

I’m trying out with Qvariant, since I’ve no control over the 3rd class which declares the virtual methods as mentioned above.

November 23, 2011

Gerolf Gerolf
Hobby Entomologist
3287 posts

The point is, if it is declared under slots, it IS parsed by moc, which results in the error. MOC does some validation and the produces a build error.

 Signature 

Nokia Certified Qt Specialist.
Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

 
  ‹‹ QWidget with QWidgetPages and how to get QListWidget information from another QWidgetPage      QDataStream for general purposes or standard c++ stream ? ››

You must log in to post a reply. Not a member yet? Register here!