How to add texture to the "basicshapes" exampler from qt3d demo - c++

I am new in Qt.
I am trying to add texture to the example project "basicshapes", which comes from Qt Creator demo.
It is written in C++ that'w perfect, because it is my need.
There are used classes such as:
Qt3D::QTransform
Qt3D::QSphereMesh
Qt3D::QPhongMaterial
and many others
but I can not realize how to add texture to it.
There is a fragment:
Qt3D::QPhongMaterial *sphereMaterial = new Qt3D::QPhongMaterial();
sphereMaterial->setDiffuse(QColor(QRgb(0xa69929)));
so I was trying to add:
MyTextureImage *t = new MyTextureImage();
MyTextureProvider *x = new MyTextureProvider();
x->addTextureImage(t);
sphereMaterial->setTextureParameter("SphereTexture", x);
before I have derived from abstract classes:
class MyTextureProvider : public Qt3D::QAbstractTextureProvider { };
class MyTextureImage : public Qt3D::QAbstractTextureImage { };
but I got error:
error: C2259: 'MyTextureImage' : cannot instantiate abstract class
due to following members:
'Qt3D::QNode *Qt3D::QNode::doClone(void) const' : is abstract

I am not an expert of Qt, however by looking at the compiler error, you would need to override the doClone method because it is qualified as pure virtual.
More information on your compiler error can be found on MSDN: https://msdn.microsoft.com/en-us/library/zxt206sk.aspx
I hope this helps.

Related

Shared pointer of a class inside a class referenced by a shared pointer gives error when trying to perform shared_from_this

This is my class structure:
class B : public std::enable_shared_from_this<B> {
}
class A : public std::enable_shared_from_this<A> {
shared_ptr<B> b_;
void SomeFunction();
}
I'm getting an error on this line:
void A::SomeFunction() {
auto a_copy = shared_from_this();
}
The error text is:
error: no matching member function for call to 'shared_from_this'
When I remove the shared_ptr<B> b_; line from class A everything works fine..
I'm guessing that there are some requirements on the object I'm trying to enable_shared_from_this on, but I tried all sorts of things and searched for the error message but to no avail..
Do you have any idea?
Well, a little embarrassing..
The problem was that I wrote shared_ptr<B> b_ instead of std::shared_ptr<B> b_. My IDE (Android Studio) didn't highlight this error in the editor, and also in the build output it didn't present the error with a link to that line, so I just skipped that line and saw only the following bug, which of course stated that there is no such function for this unknown type. I guess I got too used to the convenience of the IDE :)
Leaving this here in case someone else misses this..

UActorComponent derived class in plugin is not reacting for function calls

So I have a little problem with creating project plugin in Unreal Engine for (4.15). So let's break it down.
1.I've created MyClass that is derived from UActor Component and has also this line:
UCLASS(ClassGroup = (Custom), meta = (BlueprintSpawnableComponent))
2.I've added that component to my GameMode.
3.Then I'm trying to call any function from inside the class by Get GameMode then casting to MyGameMode and getting MyClassComponent.
4.When I'm trying to call function nothing happens at all.
I was trying to debug it but it never goes in function body but prints before function and after works perfectly fine. I also must say that when functions are compiled straight into project they work 100% fine!
This is sample of how do I declare my functions:
UFUNCTION(BlueprintCallable, Category = "MyClass|Test")
void TestFunction();
void UMyClass::TestFunction()
{
GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Red, "hello there");
}
If there is any more information required that I'm not aware of please let me know.
MyClass declaration
UCLASS(ClassGroup = (Custom), meta = (BlueprintSpawnableComponent))
class UMyClass : public UActorComponent
{
GENERATED_BODY()
public:
UFUNCTION(BlueprintCallable, Category = "MyClass|Test")
void TestFunction();
};
Any classes that need to be consumed publicly need to have their symbols exported.
In UE plugins this is achieved with the YOURPLUGIN_API specifier, where YOURPLUGIN is the name of the plugin.
This in turn is defined as __declspec(dllexport) when exporting and __declspec(dllimport) when consuming the plugin.
So your class definition should look like:
UCLASS(ClassGroup = (Custom), meta = (BlueprintSpawnableComponent))
class MYPLUGIN_API UMyClass : public UActorComponent
{
...
}

how to inherit dialogs correctly in MFC

I am building a 3d painter in C++ with OpenGL and MFC.
I created dialogs for creating every shape that i have: like cube, cylinder and etc...
My cube class inherits the cylinder class with the difference of amount of stack and slices only.
Hence the CreateCylinder dialog should look the same as the CreateCube dialog.
I was able to inherit it fine, but i have an error that says:
Error 6 error C2065: 'IDD_BASEWIN_DIALOG' : undeclared identifier c:\users\l122\desktop\opengl\opengl\basewindlg.h 19 1 OpenGL
This happens every new compilation after some minor code changes.
To fix it, i comment this line:
enum { IDD = IDD_BASEWIN_DIALOG };
then compile and uncomment the same line, which helps in the next compilation to work fine.
That how i inherited the CreateCylinder dialog class in my CreateCube dialog class:
IMPLEMENT_DYNAMIC(CreateCube, CreateCylinder)
CreateCube::CreateCube()
: CreateCylinder(this->GetSafeOwner())
{
}
CreateCube::~CreateCube()
{
}
void CreateCube::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
CreateCylinder::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CreateCube, CreateCylinder)
END_MESSAGE_MAP()
and i also edited this line in the CreateCylinder constructor:
CreateCylinder::CreateCylinder(CWnd* pParent /*=NULL*/)
: CDialogEx(CreateCylinder::IDD, this->GetSafeOwner())
The header file:
#pragma once
#include "CreateCylinder.h"
// CreateCube dialog
class CreateCube : public CreateCylinder
{
DECLARE_DYNAMIC(CreateCube)
public:
CreateCube(); // standard constructor
virtual ~CreateCube();
// Dialog Data
enum { IDD = IDD_CREATE_CUBE_DLG };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
DECLARE_MESSAGE_MAP()
};
I want to know what have i done wrong with the inheritance. is it necessary to send parent's pointer to the base dialog as i did?
And is the error above has to do anything with it?
The problem here is the scope of the enum symbol IDD_CREATE_CUBE_DLG. When you inherit a class, you don't inherit it's "symbol scope", you merely inherit its "members namespace". I'm sure some language lawyer can give a more precise (technically correct) explanation. But, a simple explanation is that you don't inherit symbol - thus enum - definitions. You should be able to access them even if they are in protected scope, though.
So, assuming that IDD_CREATE_CUBE_DLG is used in CreateCylinder class to set "its" IDD, then, instead of:
enum { IDD = IDD_CREATE_CUBE_DLG };
you should write:
enum { IDD = CreateCylinder::IDD };
I think that the correct wording would be to say that you need the "fully qualified" name here.
This is actually a good thing, and some class libraries use it to play tricks, like enumerating messages supported by a class, and such - see, for example, the FOX (widget) toolkit library.
UPDATE:
If you change your declaration as is updated here, thus avoiding the use of IDD_CREATE_CUBE_DLG, it's probable that you won't have problems with IDD_CREATE_CUBE_DLG any more. But, if you still do, the problem would be that IDD_CREATE_CUBE_DLG, since it's declared in Resource.h, then, at the time it was used (which is the line for which the error is reported), the Resource.h wasn't (properly) included. So, check what is the .cpp file that is compiled when your error is reported. Then check the includes in that file. You should clean them up, but, for starters, you may "just" #include "Resource.h" at the top (of the .h file).
As for the constructor of CDialogEx, just pass the parameter along, like this:
CreateCylinder::CreateCylinder(CWnd* pParent)
: CDialogEx(CreateCylinder::IDD, pParent)
Actually adding resource.h to my base dialog header solved the problem. I just can't understand how it worked flawlessly, before i have added the inherited classes. In both cases this header file wasn't included, so how did it work in a first place?

STK callback oscillator issue with virtual function

I am working on one of the STK programs using a Sine Oscillator callback. I am having issues when creating an object from my ToneGen class that inherits from the Generator Class due to a Virtual function in the Generator class that causes my ToneGen class to abstract. i Have tried pointers but it seems to be causing issues getting the data to the appropriate method. If i use pointers my code breaks here in the ToneGen.h file
void setRate( StkFloat rate ) { rate_ = rate; };
Otherwise without pointers i get this error
src\crtToneGen.cpp(36): error C2259: 'stk::ToneGen' : cannot instantiate abstract class
due to following members:
'stk::StkFrames &stk::Generator::tick(stk::StkFrames &,unsigned int)' : is abstract
C:\VS10 Projects\StkNewInst\crtToneGen\include\Generator.h(43) : see declaration of 'stk::Generator::tick'
Here is the Virtual Function in the Generator Class
virtual StkFrames& tick( StkFrames& frames, unsigned int channel = 0 )=0;
Is there anyway to avoid this, i have tried several other techniques on other post but have not had any luck yet.
The Code i am modifying can be found here
I am doing this on VisualStudio 2010 windows 7 32 bit
stk::StkFrames &stk::Generator::tick(stk::StkFrames &,unsigned int)
Is abstract, and needs to be implemented in your derived class
class ToneGen: public stk::Generator
{
stk::stkFrames& tick(stk::StkFrames& frames,unsigned int something)
{
return stk::stkFrames(); // Don't do this, return something useful.
}
}
You have to implement this function in your derived class as the base class provides no functionality for this method. It's declaration in the stk header would be:
stk::StkFrames &stk::Generator::tick(stk::StkFrames &,unsigned int) = 0;

Source SDK Compile Errors

I am making a Counter Strike mod and during compiling I am getting some errors:
Panel.cpp(715): error C2248: 'CInput::CVerifiedUserCmd' : cannot access private class declared in class 'CInput'
1> \SDK\\game\\client\\input.h(238) : see declaration of 'CInput::CVerifiedUserCmd'
1> \SDK\\game\\client\\input.h(39) : see declaration of 'CInput'
Line 715:
CInput::CVerifiedUserCmd* ver = NULL;
Declaration:
class CVerifiedUserCmd
{
public:
CUserCmd m_cmd;
CRC32_t m_crc;
};
How do I fix this?
You're probably trying to use a private inner class:
class A
{
class B
{
};
};
Simply make the class public if you wish to use it outside:
class A
{
public:
class B
{
};
};
EDIT:
If the class is private and it's part of a 3rd party lib, you're probably doing it wrong. Look for a different solution to your problem, it was made private for a reason.
Assuming that was your code put class
CVerifiedUserCmd
to public section of the outer class. Otherwise you cannot use CVerifiedUserCmd since it is private inner class.
You probably can't (unless you want to edit the engine itself) - look for a better solution to your problem. Basically, don't try to manually instantiate CInput::CVerifiedUserCmd.