wxWidgets - Splitting project into multiple files - c++

I am very new to C++, I'm making this music application using wxWidgets, this is my first project in C++. As of now, I have 4 files, app.hpp and app.cpp which has a class that inherits from wxApp that launches the application, and frame.hpp and frame.cpp which holds the base frame and panel, and all the widgets, and their appropriate functions. I want to move all the functions to a separate file, but I get some errors like there is this function in frame.cpp
void Frame::ClearPlaylist(wxCommandEvent& event)
{
mediaCtrl->Stop();
playlistBox->Clear();
}
I tried moving it in another file called command.cpp and created a new class called command and prefixed all functions to Command:: .... and somethings like the playlistBox here, is a widget which I want in frame.cpp only, as it is a widget, so I did #include frame.hpp and prefixed it with Frame::playlistBox, but that gave a error saying invalid use of non static data member. So do I have to make everything in frame.hpp a static object? Or if anyone has a better solution for organizing a project like this please do share.

Related

Open a Window in JUCE and put a PluginEditor into it

The tl;dr How do I open a window in Juce to display a plugin Editor?
I am following the Juce AudioProcessGraph tutorial at https://docs.juce.com/master/tutorial_audio_processor_graph.html which shows how to dynamically load AudioProcessor objects.
I would like to open their GUIs as they're loaded. This could be in separate windows or in the window that's got the slots for the graph.
I've tried creating a AudioProcessorEditor, but I'm at a loss on how to tell it to open.
Edit to add: What I've tried so far:
I've downloaded the code from the Tutorial: Cascading plug-in effects from https://docs.juce.com/master/tutorial_audio_processor_graph.html
I've also used ProJucer to create a new plugin. I've put the new plugin's files into the tutorial's files and used ProJucer to add PluginEditor.cpp and PluginEditor.h to the tutorial project.
I've changed the PluginEditor.h so the private class member audioProcessor is of type ProcessorBase&. And made ProcessorBase& the expected type for the data passed to the constructor.
In the tutorial code, in the header file, I've changed the ProcessorBase class so that the methods hasEditor() and createEditor() are just declarations and then modified main.cpp as follows:
#include "PluginEditor.h"
#include <iostream>
//=======================================================
juce::AudioProcessorEditor* ProcessorBase::createEditor()
{
std::cout "asking for an editor\n";
return new NewProjectAudioProcessorEditor (*this);
}
bool ProcessorBase::hasEditor() const
{ return true; }
In the included header, in the TutorialProcessor class, in the updateGraph() method, under the if (hasChanged), I've added slot->getProcessor()->createEditorIfNeeded (); on line 387-ish.
I can tell from my cout that createEditor() is being called and know that the constructor for the editor is running, but no window opens.
How do I tell it to open a window?
The code compiles and runs, but no window opens.

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.

QT Creator Main.cpp MainWindow.cpp

I'm currently working on my project for my Master thesis in Mechatronics/Robotics. The goal of y project is to read in a .stl-File and calculate the path for an industrial robot.
Till now everything worked fine for me, but now my professor wants me to develop a GUI, because till now I was just using the command window and wrote all parameters manual. Now I'm working with Qt Creator and developed a simple GUI for my project.
In this interface I got a RadioButton for ascii files. In order my functions work I have to determine if the user is entering a ascii file or an binary file. But here's my first problem. In the command window I just check the argv[] for the string "-ascii". If the user enters this, a flag is set to false.
if(0 == strcmp(argv[i], "-ascii")) {
isBinaryFormat = false;
}
Now I just want to do the same int the GUI. If the RadioButton is checked flag is set to false. So I wrote the following in the main.cpp file
if(ui->radioButton->isChecked()) {
isBinaryFormat = false;
}
But ui is unknown in the main function. After searching for help on google I just found tutorials writing the code in the mainwindow.cpp file. But how can I send the information form the mainwindow file to my main function in the main.cpp file.
A second question would be, if I use the QFileDialog::getOpenFilename method, how can I hand the file name to my other functions. The idea is, the user selects a file anywhere on his PC, and the program opens the file and processes it. But here I got the same problem. I can brows for a file, but how can I transfer the information from the mainwindow.cpp to my main.cpp.
I'm thankful for any help I get. Very grateful a lonely coder
First of all you don't write UI Code in the main.cpp.
You write it where the MainWindow Class is so in MainWindow.cpp and MainWindow.h.
Then your ui-> will work because it then has access to that namespace.
I don't see why you would have functions in Main.cpp?
Without seeing more code you're not likely to get an answer to that.
If you want to use external functions in your classes either declare the methods in the class directly or create a new file like global_function.h and .cpp which you can include in your class. ( don't forget the header guards )
Also shouldn't that code look like this:
if(!ui->radioButton->isChecked())
{
isBinaryFormat = false;
}
because of:
If the RadioButton is checked flag is set to false.
QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"),
"/home",
tr("Images (*.png *.xpm *.jpg)"));
getOpenFileName( ) will return a string containing the path and filename of the selected file which you can pass to your functions then.
Please read some more about how to use Qt.
It's not just about the files, there's a class, too. Learn about them. Solution is to add a getter to your MainWindow class that will return whether the radioButton is checked:
class MainWindow : public QMainWindow
{
public:
// optionally, move implementation in the source file
bool isBinaryFormatChecked() const
{
return ui->radioButton->isChecked();
}
// other stuff ...
};
And then you can access it in your main like window.isBinaryFormatChecked() orwindow->isBinaryFormatChecked() depending on whether you have a pointer or not. Another way would be to make ui in your MainWindow public, so you could access the whole user interface, but that breaks proper encapsulation.
I think you need to go through a few of the (excellent in my opinion) examples supplied with Qt before attempting to integrate your already working console code.
Essentially you really don't want to do that check in the main.cpp, but if you must you could have it in a public function of the mainwindow and call that from your main.cpp file. But then that doesn't really make sense as you don't want to check whether the appropriate radio button is set until the user inputs something. You're going to have to read up on event based programming.

C++ -> Visual Studio 2013 -> Windows Form -> Objects accessed through methods

Hello once again I am asking some experts for help. This time it is not about Linux commands but Visual Studio 2013 Windows Form in C++.
As always, details :
I have project with 2 forms, that's not really important.
Important things are :
I have 6 files : Windows.h, Windows.cpp, Game.h, Game.cpp, Test.h,Test.cpp
Including : Windows.cpp includes Windows.h, Windows.h includes Game.h, Game.h includes Test.h, Test.cpp includes Test.h as well.
Windows.h and Game.h are form declarations. This is where I need work to be done.
Windows. cpp is used as main, it executes whole project and do stuff.
Windows.h is Form for Menu, it just connects to Game.h Form and becomes hidden when Game appears.
Game.h is Form with game. I need to create and operate on objects in methods included in Forms connected to Buttons.
Example : Click on one button creates one object class Test with variable int number = 1 and click one other button changes this variable to 2.
I can't access same object through methods, all I can do is create two same objects and operate on them but they are different beings declared in other method. Is there any solution to construct object which can be accessed through every Form's method ?
Test.h
#pragma once
ref class Test
{
public:
int nr;
char *test;
Test();
Test(int n, char *t)
{
nr = n;
test = t;
}
};
Test.cpp
#include "Test.h"
Test::Test()
{
}
I declared objects in class Game as variables what gave me access to those objects in Game's method.

Qt Designer undefined symbol with Custom Widget plugin

I am using Qt 4.7.2 under Fedora 14.
I have a working library of custom widgets which I am trying to integrate into Qt Designer.
There is a simple widget base class, then some more complex widgets inheriting from it.
The simple widget integrates fine, but I have a problem with the more complex ones.
The problem comes from the fact that that the more complex ones require a special structure to be passed to them on creation. So my code for creating a complex widget in the plugin is:
QWidget *myPlugin::createWidget(QWidget *parent)
{
my_struct *xyz = new my_struct;
return new myWidget("MyWidget",xyz, parent);
}
my_struct is just a simple C style struct with ints, doubles and arrays.
Then when I start Qt Designer with this plugin I get:
/usr/lib64/qt4/bin/designer: symbol lookup error: /usr/lib64/qt4/plugins/designer/libMyPlugin.so: undefined symbol: _ZN8MyWidgetC1E7QStringP17my_structP7QWidget
I am building a release version of the plugin, not a debug version.
I also tried defining xyz as a static class variable in the plugin and just passing its address to the constructor, but I still get the same error.
I also tried adding xyx as an unused static class variable to my simple widget and that does not give the error, so the error seems to be coming from the call to the myWidget constuctor.
Can anyone help me resolve this?
Thanks Arne,
You were right.
I added my library explicitly to the plugin's .pro file and then it worked.
What puzzles me is how could I build the plugin with no errors without the library?
And why did my simple widget work without the library?
The error message looks as if the linker did not find a definition for the constructor myWidget(QString, my_struct*, QWidget*). Have you added the relevant source file to your release build? Do you actually have a definition for this constructor? It is also possible that you have to exchange the object file linking order. I have seen this with larger projects in the past, so I wouldn't be too surprised. The object file containing the definition needs to be stated before the one using the definition.