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)
-
COM project created by selecting the QT project type (Active Qt Server)
-
I removed all the UI components and derived from QObject (When I'm deriving from QWidget, I can't call from a console application).
-
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- Now I'll present some pseudo-code and will describe about the problem.
I've a 3rd party virtual class ,
@
thirdParty.hthirdParty: public IUnknown { public: virtual /* [helpstring] */ HRESULT STDMETHODCALLTYPE Init( /* [out][in] */ LPTNTDRVINFO pDrvInfo) = 0; /// some more... };
Myclass.h // interface
#include <ActiveQt/QAxBindable>
#include "Myclass_global.h"
#include "IEC61850ErrorCodes.h"
#include <qobject.h>class MYCLASS_EXPORT IEC61850DriverClass : public QObject, public QAxBindable , public thirdParty
{Q_OBJECT
public:
IEC61850DriverClass( QObject *p = 0);// STDMETHOD(method) , will refer some windows specific file and boils down to ( __declspec(nothrow) long __stdcall method ) // ObjBase.h
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"
///SOME MORE...ULONG STDMETHODCALLTYPE AddRef( void);
ULONG STDMETHODCALLTYPE Release( void);
STDMETHOD(QueryInterface)(
/* [in] / REFIID riid,
/ [iid_is][out] */ __RPC__deref_out void __RPC_FAR *__RPC_FAR *ppvObject);public slots:
QString getdata(); // Only this method we can see as exposed from COM( through C# noticed)
- //But, my actual requirement is putting "Init()" here, which resulting in parse erro. No idea how to solve it.*
STDMETHOD(Init) ( LPTNTDRVINFO pDrvInfo); //[eg: long Initialize( LPTNTDRVINFO pdata),Inside which I'll be calling Init( LPTNTDRVINFO p),but no success]
private:
QString data;
};Myclass.cpp // implementation
#include "stdafx.h"
#include "maptagtableclass.h"
#include "Myclass.h"
#include <ActiveQt/QAxFactory>STDMETHODIMP IEC61850DriverClass::Init(LPTNTDRVINFO pDrvInfo) {
return OLE_E_NOCONNECTION;
}
// some code....
stdafx.h // contains all the declarations.
#include "logger.h"
#include <tchar.h>
#include "..\Include\Drv\thirdPart.h" // declarations like "LPTNTDRVINFO etc" ..
#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 :(.
-
-
It would be helpful if you told us the actual error message.
-
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 ========== -
After doing further analysis I've reached to some what specific issue with QT framework.
MyClass.h
@
// Refer above ...
LineNo:48 STDMETHOD(Init) ( LPTNTDRVINFO pDrvInfo); // earlier ..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.
-
Hi,
LPTNTDRVINFO , is a structure type, declation in this form ,
@
typedef struct {// bla bla
}DRVINGO, *LPTNTDRVINFO;
@ -
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":http://doc.qt.nokia.com/4.7/qmetatype.html#qRegisterMetaType docs for details.
-
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.
@
Line 45: QString getdata();
LineNo:48 QString intialize ( LPTNTDRVINFO pDrvInfo); // LPTNTDRVINFO, un-supported type.
@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!!!
-
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).
-
Hi,
As a side note: STDMETHOD declares a method as:
@
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.
-
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.
-
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.