[Qt-interest] Qt C++ with some C++.NET calls
Sylvain Pointeau
sylvain.pointeau at gmail.com
Sat Jan 16 12:32:17 CET 2010
Hello again,
it is working!
that's purely great :-D
in a .h
#include <QString>
struct TestImpl;
class Test {
private:
TestImpl *d;
public:
Test();
~Test();
void setName( QString x );
int myint();
};
in the .cpp
#include <vcclr.h>
#include "guid.hpp"
using namespace System;
struct TestImpl {
gcroot<String^> name;
};
Test::Test() {
d = new TestImpl;
}
Test::~Test() {
delete d;
}
void Test::setName( QString x ) {
d->name = gcnew String((const wchar_t*)x.utf16());
}
int Test::myint() {
return d->name->GetHashCode();
}
I set the compiler option to use the CLR for this .cpp file.
and I can use my unmanaged class in my Qt native application,
and it uses the .NET behind the scene.
great, really great!!
Please don't hesitate if you have any comments...
Best regards,
Sylvain
On Sat, Jan 16, 2010 at 11:42 AM, Sylvain Pointeau <
sylvain.pointeau at gmail.com> wrote:
> Hello,
>
> if I do that in my project then I have a lot of errors:
> Error 29 error C2182: 'at' : illegal use of type 'void'
> c:\qt\4.6-vs2008\src\corelib\tools\qvector.h 143 website_runner
> Error 30 error C2182: '[]' : illegal use of type 'void'
> c:\qt\4.6-vs2008\src\corelib\tools\qvector.h 144 website_runner
> Error 31 error C2182: '[]' : illegal use of type 'void'
> c:\qt\4.6-vs2008\src\corelib\tools\qvector.h 145 website_runner
> Error 32 error C2182: 't' : illegal use of type 'void'
> c:\qt\4.6-vs2008\src\corelib\tools\qvector.h 146 website_runner
> Error 33 error C2182: 't' : illegal use of type 'void'
> c:\qt\4.6-vs2008\src\corelib\tools\qvector.h 147 website_runner
>
> I found to compile some file as managed code, and I think it will work
> I am still experimenting this way.
>
> a very good link:
>
> http://msmvps.com/blogs/vandooren/archive/2008/09/03/extending-a-native-c-project-with-managed-code.aspx
>
> Best regards,
> Sylvain
>
> On Sat, Jan 16, 2010 at 9:00 AM, Gino VH <ginovh2002 at yahoo.com> wrote:
>
>> Hello,
>>
>> with some small changes to the generated vcproj file I could compile this
>> "hello world" .NET program with Qt.
>> I am not sure this flow will work for you. But you can give it a try.
>>
>> #include <QApplication>
>> #include <QLabel>
>> int main(int argc, char *argv[])
>> {
>> System::Console::WriteLine("Hello, World!");
>> QApplication app(argc, argv);
>> QLabel *label = new QLabel("Hello Qt!");
>> label->show();
>> return app.exec();
>> }
>>
>> What I did:
>> 1) Build Qt for VS2008 (I guess you already have build, but it is
>> important you build as dynamic lib, which is the default):
>> configure.exe -debug-and-release -platform win32-msvc2008
>> nmake sub-src
>> nmake sub-tools
>> 2) make Qt project like you always would do for Qt
>> qmake -project
>> qmake -tp vc hello.pro
>> 3) Modify the project settings in VS IDE for CLR code:
>> Project properties >> Configuration Properties >> General >> Common
>> language runtime support >> Common language runtime support /clr
>> Project properties >> Configuration Properties >> C/C++ >> Code Generation
>> >> Enable C++ exceptions >> No
>>
>> Make sure if you want to see console output that you have this line in
>> your .pro file :
>> CONFIG += console
>>
>> this worked in my case.
>>
>> good luck,
>>
>> Gino
>>
>>
>>
>>
>> _______________________________________________
>> Qt-interest mailing list
>> Qt-interest at trolltech.com
>> http://lists.trolltech.com/mailman/listinfo/qt-interest
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100116/30877a5a/attachment.html
More information about the Qt-interest-old
mailing list