Unable to compile Qt project using qlogvalueaxis.h - c++

I am currently working on a C++ application for controlling an instrument. The instrument output should be displayed using a QChart. For the display I created a Qt user interface with a QChartView widget.
Here is the header file for the display class:
#pragma once
#include <QWidget>
#include "QtCharts\qchart.h"
#include <QtCharts\qchartview.h>
#include <QtCharts\qscatterseries.h>
#include <QtCharts\qlineseries.h>
#include "ui_ChartsDisplay.h"
#include <qthread.h>
using namespace QtCharts;
class ChartsDisplay : public QWidget
{
Q_OBJECT
public:
ChartsDisplay(QWidget *parent = Q_NULLPTR);
~ChartsDisplay();
private:
Ui::ChartsDisplay ui;
QLineSeries *trace,*retrace,*arbitrarySeriesX,*arbitrarySeriesY;
QChart *chart;
//QLogValueAxis *axisX, *axisY;
void rescaleChart();
public slots:
void SLUpdateChart(float *newValues);
void SLSetupChartDisplay(int type);
void SLResetChart();
void SLUpdateNoise(float** newValues, int size);
};
I need two instances of the ChartDisplay class. One with linear and one with logarithmmic scaling for displaying different data types.
I found a Qt tutorial on using logarithmic axis scaling here:
https://doc.qt.io/qt-5/qtcharts-logvalueaxis-example.html
However, once I include "qlogvalueaxis.h" my programm will no longer compile. I get a long list of syntax errors originating in "qlogvalueaxis.h".
I created a new Qt project and implemented a simple chart with logarithmic scaling using qlogvalueaxis which worked fine.
Also I cleaned the whole project and removed all qt generated files before compiling. The problem still remained.
All necessary libraries are linked and up to date as are the header files.
Some information about the environment:
-Visual Studio 2015, community edition
-Qt framework 5.8
-Operating system is Win 7
Any would appreciate any advice.
Best regards,
T. Krastev

I had a similar (or perhaps the same) problem. I got compile errors indicating that the min() and max() function prototypes were already declared elsewhere, so if this is the case for you simply omit the min and max macros by adding the following before including the QtCharts headers:
#ifdef max
#undef max
#endif
#ifdef min
#undef min
#endif

Related

Call c++ function in Widget blueprint

I create widget, inherited from C++ class below.
#pragma once
#include "CoreMinimal.h"
#include "Blueprint/UserWidget.h"
#include "Widget_Manager.generated.h"
UCLASS()
class CRY_API UWidget_Manager : public UUserWidget
{
GENERATED_BODY()
public:
UPROPERTY(BlueprintReadWrite, Category ="test")
int32 x;
UFUNCTION(BlueprintCallable, Category = "test")
int32 increase_x(int32 i);
};
I want to output the value of x in value1, then increase it, and output it to value2.
My problem is that the blueprints do not see the function increase_x().
Not in elements list, not in function search.
Also i tried property CallInEditor.
How I can call this function in widget?
Please make sure that your not using Hot Reload (the Compile C++ button in the Editor).
If you make changes to your C++ code, especially Headers, always close the Editor and recompile it from Visual Studio. Hot Reload cannot resolve changes to Header files, which means things like Functions and new Properties will not be available in Blueprint if your using Hot Reload until you do a recompile from Visual Studio.
Also its best to leave Context Sensitivity on.

Load OpenGL function pointers using glad withing a QOpenGLWidget

So I am reading up on some OpenGL and I want to use the QOpenGLWidget for drawing to maybe create some other helpful UI elements later. I am using glad for resolving the function pointers to OpenGL but I have no idea how to use Qt's getProcAddress function!
Inside my QOpenGLWidget subclass' initializeGL() function I have tried:
if(gladLoadGLloader((GLADloadproc) currentContext()->getProcAddress) {}
but that did not work out since Qt's function is overloaded. When I use
if(gladLoadGL()) {}
it doesn't work either. My includes are:
#include <glad\glad.h>
#include "OpenGLViewport.h"
#include <QDebug>
#include <QOpenGLContext>
I have searched Mr. Google and I've had a diligent look through the Qt documentation and found nothing. I want to use GLAD just so my rendering code is not bound to Qt too tightly, in case I want to switch later.
EDIT: I am aiming to use the noninstanced OpenGL functions with Qt (though the documentation recommends otherwise if I recall correctly). Because then I'd be able to seemlessly switch to GLFW for providing a window etc.
Moved solution from question to answer:
ANSWER: So it turns out I just had some things mixed up, this is how I got it to work, in case anyone has the same problem:
add glad.c in your project
add the necessary headers to your include directory
the .cpp file of your QOpenGLWidget subclass should have following components:
// Subclass.cpp
#include <glad/glad.h>
// important, subclass header file after glad!!
// otherwise glad won't "hook"
#include "Subclass.h"
void Subclass::initializeGL()
{
if(gladLoadGL()) initialized = true; // initialized is a class member here
else; // handle errors
}
void Subclass::paintGL()
{
if(initialized); // render here
}

AActor *UactorComponent::GetOwner const - pointer to incomplete class type is not allowed

I'm new to UE4 development and I've followed Udemy's Unreal Engine Development course. I have created a new Component on an Actor, named PositionReporter with header PositionReporter.h
#pragma once
#include "CoreMinimal.h"
#include "Components/ActorComponent.h"
#include "PositionReporter.generated.h"
UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class BUILDINGESCAPE_API UPositionReporter : public UActorComponent
{
GENERATED_BODY()
public:
// Sets default values for this component's properties
UPositionReporter();
protected:
// Called when the game starts
virtual void BeginPlay() override;
public:
// Called every frame
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
};
and code in PositionReporter.cpp being
#include "PositionReporter.h"
// Sets default values for this component's properties
UPositionReporter::UPositionReporter()
{
// Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these features
// off to improve performance if you don't need them.
PrimaryComponentTick.bCanEverTick = true;
// ...
}
// Called when the game starts
void UPositionReporter::BeginPlay()
{
Super::BeginPlay();
FString t = GetOwner()->GetActorLabel();
UE_LOG(LogTemp, Warning, TEXT("Position Reporter reporting for duty on %s"), *t);
}
// Called every frame
void UPositionReporter::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
// ...
}
As you can see, I am now trying to call the GetName function on the Pointer to the AActor retrieved through GetObject().
However, as soon as I type "GetObject()->" no autocomplete pops up (as it does in the video) and when I add "GetName()" manually, I get the compiler error "pointer to incomplete class type is not allowed".
What am doing wrong? Am I missing an import or so? I already compared my code to Ben's git repo but can't find any differences. I am on unreal editor 4.16.0!
I noticed another strange thing: When I compile everything from Unreal Engine Editor, it compiles and runs fine. But when I compile it with VS 2017 I get the error, and I also dont get the Autocomplete, which is a real bummer. What am I missing?
Including Engine.h on PositionReporter.h fixes the issue.
#pragma once
#include "Engine.h" // <- This
#include "CoreMinimal.h"
#include "Components/ActorComponent.h"
#include "PositionReporter.generated.h"
You'll need to give Intellisense some time... As a matter of fact I closed and reopened the solution for it to stop showing the non existing errors and give autocomplete functionality.
NOTE: As is mentioned in other posts, this solution is good to get intellisense autocompleting but isn't the best as it will include a ton of stuff and greatly increase compilation times.
Including the specific .h file would be better, but you need to know what .h to include, and probably you don't know it.
Best solution I found is ditching Intellisense and use Resharper for code autocompletion, it works fast, autocompletes correctly and you don't need to include any extra file.
I would like to point out that including "Engine.h" is going against the IWYU rationale from Unreal 4.15 onwards, because Engine.h is huge and slows down compile time. See the Unreal Documentation for more information on the matter. So although it solves the problem, and there is nothing particularly 'wrong' with doing it - it may not be the best idea.
Another option which is more in line with IWYU would be to include Actor.h in PositionReport.cpp since GetOwner is in the AActor class.
#include "PositionReport.h"
#include "GameFramework/Actor.h" //This is the change in PositionReport.cpp

Arduino: how to use object of other class as arguments of my library?

I'm breaking my head trying to use Servo.h inside of a library I made. The compiler consistently gives me the same error, as if it does not recognize the class, which is included in my library.
I am trying to make a new class, one of it's properties is a Servo object, which I should pass in the constructor. No matter how I try, I keep receiving the same error message when trying to compile my sketch:
In file included from /home/nezah/Arduino/My
sketches/CameraShutter/CameraShutter.ino:8:0:
/home/nezah/Arduino/libraries/Shutter/Shutter.h:13:19: error: expected
')' before '*' token
Shutter(Servo *servo);
It seems that the include statement is ok, as I get a different message if I mess it to go wrong or remove it completely. I already tried to change "" for <> and even copied the source in a folder and use the full path. No change as far as I don't mess it (on purpose). I already read this.
I also tried to pass it as a pointer, using Shutter(Servo* servo), Shutter(Servo *servo) and Shutter(Servo& servo). Same error message.
In some arduino.cc forum I read that I rather forget it and avoid using libraries inside other libraries, but I bet this is possible.
Is there anybody so kind as to give me some hints on how to do this?
I leave you part of my .h and .cpp of the library I'm trying to write (which, by the way, turns a servo into a physical button presser but with burst capability).
/*
* Shutter.h - Library to make a photocamera shutter out of a servo
* alternatively it could press any physical button with a servo.
*/
#ifndef Shutter
#define Shutter
#include "Servo.h"
class Shutter {
public:
Shutter(Servo *servo);
Servo getServo();
void shut();
private:
Servo _servo;
}
#endif
And here is my .cpp:
/*
Shutter.cpp - Library for flashing Shutter code.
Created by David A. Mellis, November 2, 2007.
Released into the public domain.
*/
#include <Arduino.h>
#include "Servo.h"
#include "Shutter.h"
Shutter::Shutter(Servo *servo) {
_servo = servo;
}
NOTE: If I remove some code and take away the "Servo" part of the constructor, I get an error message on the "getServo()" code. The problem seems to be that the compiler does not recognize "Servo" as a valid type inside my library.
Thanks in advance!
In the constructor of your class you are passing a pointer of the type Servo, so you must store that value in another pointer. To do this you must change:
*.h
#ifndef SHUTTER_H
#define SHUTTER_H
#include "Servo.h"
class Shutter {
public:
Shutter(Servo *servo);
Servo *getServo() const;
void shut();
private:
Servo *_servo;
}
#endif
*.cpp
Shutter::Shutter(Servo *servo) {
_servo = servo;
}
Servo *Shutter::getServo() const
{
return _servo;
}
Use:
Servo servo;
Shutter shuter(&servo)
Looks like the problem was that the class name and the #ifndef marker was the same, so there was a name conflict somehow. It is well explained in this thread: How to properly use a header file to be a complete class?
After fixing this, it compiled well.

Visual Studio not building correctly

I've been having two different problems when trying to compile a C++ project today.
Sometimes it won't reflect any of my changes in the new build: If I change some wording on the output or change around actual functionality and compile and hit Start Debugging, it will behave exactly as it did before I made the changes. Hitting Clean or Rebuild Solution fixes this, but it takes about a full minute to compile this. I guess it's not detecting any changes, but in the output window I see it list the file names of files I made changes to...
I'm also getting a lot of "...already defined in main.obj" errors (one for every function and variable) whenever I try to use a header file or define a function outside of a class. Renaming the functions lets it compile once, but then the second compile will bring up the errors again. It kinda works if I just define the class in a .cpp file, don't use a header file, and don't use any functions outside of the class.
The project is an open-source program I downloaded the other day to mess with (I'm building a bot to control it). I didn't have the first problem until today, but the second one's always been happening. All I've done is add a file (two if you count both Bot.cpp and Bot.h); Bot.cpp includes Bot.h and some files from the program, and the program's main.cpp includes Bot.cpp.
I'll post some code I guess, but I can't find anything wrong with what I'm doing. I'm wondering if there's something I need to do to the existing files? (there were VS solution files included with the project that I used to open it, since VS Express doesn't help you create projects from existing code.)
//Bot.h
#ifndef _Bot_h_
#define _Bot_h_ 1
#include <string>
class Bot{
private:
uint32 inputs = 0;
bool active = false;
public:
Bot(){};
~Bot(){};
void Start();
void Stop();
void Run();
void Wait(int seconds);
void Press(int buttons);
};
#endif
//Bot.cpp
#ifndef _Bot_cpp_
#define _Bot_cpp_ 1
#include "main.h"
//Some other project files included between these
#include "Bot.h"
using namespace std;
void Bot::Start(){
if (active == false){
active = true;
Run();
}
}
void Bot::Stop(){
active = false;
}
void Bot::Run(){
while (active == true){
printf("Has my code updated?\n");
Wait(2);
}
}
//There are more functions defined here
#endif
All I've really done in the original source code is include Bot.cpp at the bottom of the list of includes in the main.cpp file, and then add a call to create the class. I'm a little out of practice with C/C++ so maybe it's something simple. I'm also bad at writing posts like this so if anything needs clarified I'll try to help.