Hey guys this is my code and i am relatively new to C++ and even coding really dont know why i am getting a parse error
though i as per my understanding i have placed the parenthesis properly anyone please suggest if i am missing anything here.
i am getting error at this line
class getProcessor()->RequestUIUpdate()// UI update must be done each time a new editor is constructed
Full Code:
StereoWidthCtrlAudioProcessorEditor::StereoWidthCtrlAudioProcessorEditor (StereoWidthCtrlAudioProcessor* ownerFilter)
: AudioProcessorEditor(ownerFilter)
{
addAndMakeVisible (WidthCtrlSld = new Slider ("Width Factor Slider"));
WidthCtrlSld->setRange (0, 5, 0.1);
WidthCtrlSld->setSliderStyle (Slider::LinearHorizontal);
WidthCtrlSld->setTextBoxStyle (Slider::TextBoxLeft, false, 80, 20);
WidthCtrlSld->addListener (this);
addAndMakeVisible (BypassBtn = new TextButton ("Bypass Button"));
BypassBtn->setButtonText (TRANS("Bypass"));
BypassBtn->addListener (this);
addAndMakeVisible (label = new Label ("new label",
TRANS("Stereo Width Factor:")));
label->setFont (Font (15.00f, Font::plain));
label->setJustificationType (Justification::centredLeft);
label->setEditable (false, false, false);
label->setColour (Label::textColourId, Colour (0xffa34747));
label->setColour (TextEditor::textColourId, Colours::black);
label->setColour (TextEditor::backgroundColourId, Colour (0x00000000));
//[UserPreSize]
//[/UserPreSize]
setSize (600, 400);
//[Constructor] You can add your own custom stuff here..
class getProcessor()->RequestUIUpdate()// UI update must be done each time a new editor is constructed
startTimer(200)//starts timer with interval of 200mS
BypassBtn->setClickingTogglesState(true);
//[/Constructor]
}
StereoWidthCtrlAudioProcessorEditor::~StereoWidthCtrlAudioProcessorEditor()
{
//[Destructor_pre]. You can add your own custom destruction code here..
//[/Destructor_pre]
WidthCtrlSld = nullptr;
BypassBtn = nullptr;
label = nullptr;
//[Destructor]. You can add your own custom destruction code here..
//[/Destructor]enter code here
}
class is a keyword mainly used in declarations. You probably meant:
getProcessor()->RequestUIUpdate();
Related
I'm creating a Basic Button event for a University Project and I'm having problems trying to access an Entity's child.
I am using a Component model in order to create and display all objects on the screen and one "button" is comprised of 3 separate components, a TextComponent that displays what the button does i.e. "Start Game", a SpriteComponent that creates and displays an image above the text, and a ShapeComponent that acts as a "Bounding Box" for my button. This component functions purely as a sort of Event Handler, checking to see if the mouse is inside the shape's bounding box and if so, allows the user to interact with it (like display a message).
Below is the code for one of my buttons.
static shared_ptr<Entity> btnStartGame;
void MainMenuScene::Load() {
//START GAME BUTTON
auto txtNewGame = makeEntity();
auto t = txtNewGame->addComponent<TextComponent>("New Game");
t->getText().setOrigin(t->getText().getGlobalBounds().width / 2, t->getText().getGlobalBounds().height / 2);
txtNewGame->setPosition(Vector2f(280.f, 500.f));
auto sword = makeEntity();
auto s = sword->addComponent<SpriteComponent>();
s->Sprite("Sword.png", IntRect(0, 0, 60, 60));
sword->setPosition(Vector2f(370.f, 540.f));
auto btnStartGame = makeEntity();
auto b = btnStartGame->addComponent<ShapeComponent>();
b->setShape<sf::RectangleShape>(Vector2f(200.f, 105.f));
b->getShape().setFillColor(Color(224, 190, 20)); //just so I can see where it is
b->getShape().setOrigin(b->getShape().getGlobalBounds().width / 2, b->getShape().getGlobalBounds().height / 2);
btnStartGame->setPosition(Vector2f(Engine::GetWindow().getSize().x / 4 - 40.f, 525.f));
}
Once the Bounding box is created, I do a validation check in the Update function in order to see if the mouse is currently inside the ShapeComponent's bounding box. I get the component of the btnStartGame Entity and get it's GlobalBounds, after this is done, I check to see if the mouse is currently inside the box However this line causes an error.
if (btnStartGame->get_components<ShapeComponent>()[0]->getShape().getGlobalBounds().contains(Engine::GetWindow().mapPixelToCoords(sf::Mouse::getPosition())))
{
cout << "level 1 selected" << endl;
}
I get a Read Access Violation Error at this line in Vector
pointer _Unchecked_begin() _NOEXCEPT
{ // return pointer for beginning of mutable sequence
return (this->_Myfirst());
}
Does anyone know why this is happening? I thought at first it was a pointer error but that didn't seem to fix anything.
Solved the problem.
I had created a shared_ptr and instead of referencing the Entity I had created, I was trying to point to a new one inside the Load() function.
Removing the Auto from btnStartGame solved the issue
btnStartGame = makeEntity();
Good day! I don't know if my title is right. please change if not :D
Anyway, I do have 3 Rectangles added to List<Rectangle> and load it up
given them a class that has event [ Paint / MouseDown / MouseUp / Mousemove ] each of them.
Now, the 3 Rectangle that has class are now currently running.
Now, when I removed 1 Rectangle in List<Rectangle>
and load it up again, the removed Rectangle still running.
How can I dispose class or classes that are currently running?
thank you!
found a solution.
public EventHandlerList DetachEvents(Component obj)
{
object objNew = obj.GetType().GetConstructor(new Type[] { }).Invoke(new object[] { });
PropertyInfo propEvents = obj.GetType().GetProperty("Events", BindingFlags.NonPublic | BindingFlags.Instance);
EventHandlerList eventHandlerList_obj = (EventHandlerList)propEvents.GetValue(obj, null);
EventHandlerList eventHandlerList_objNew = (EventHandlerList)propEvents.GetValue(objNew, null);
eventHandlerList_objNew.AddHandlers(eventHandlerList_obj);
eventHandlerList_obj.Dispose();
return eventHandlerList_objNew;
}
wxTextCtrl causes some memory allocation problem when tried to be deleted or it's value changed. Here's some code insight:
wxTextCtrl* s = new wxTextCtrl(...);
s->SetValue("abc");//crash
delete s//crash
It's like all of its members are const's. Here is what VisualStudio says when it crashes:
An unhandled exception of type 'System.AccessViolationException'
occurred in Unknown Module.
Additional information: Attempted to read or write protected memory.
This is often an indication that other memory is corrupt.
And even when i try the wxWidgets default destroy:
parent->DestroyChildren(); //ofc the parent is wxPane passed in constructor of s
Any help will be appreciated.
Here's some actual code from the only functions calling wxTextCtrl:
void AddButton::OnAction(wxSize* frame){
if ( !DoAction ){
if ( ! thy )
{
thy = new wxPanel
(mParent, -1,
wxPoint(0, 0),
wxSize(PanelWidth, mParent->GetSize().GetHeight()),
wxBORDER_NONE | wxFRAME_FLOAT_ON_PARENT );
thy->SetBackgroundColour(wxColor(30,30,30));
thy->Show();
if ( ! AddPanelDialog ){
//AddPanelDialog = (new _Text
//(this, thy, "add link...", wxPoint(1, 30), wxSize(PanelWidth - 30, 20),
//wxBORDER_NONE | wxTE_PROCESS_ENTER ));
wxTextCtrl* s = new wxTextCtrl(thy, -1, "", wxPoint(1, 30), wxSize(PanelWidth - 30, 20),
wxBORDER_NONE | wxTE_PROCESS_ENTER );
s->Connect(wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler(_Text::OnEnter));
s->Show();
}
if ( !ConfirmPanel ){
ConfirmPanel = new wxPanel
(thy, -1, wxPoint(PanelWidth - 28, 30), wxSize(27, 20),
wxBORDER_NONE | wxFRAME_FLOAT_ON_PARENT );
ConfirmPanel->SetBackgroundColour(wxColor(38, 145, 232));
ConfirmPanel->Show();
}
}
else {
thy->Show();
}
gui* rmd = (gui*)mParent;
rmd->LeftPanelActivate();
rmd->SetNewPositions(rmd->GetParent()->GetSize());
Button::Update();
helper::SendRedrawEvent(mParent);
DoAction = true; // indicates action activated
}
else{
thy->Hide();
gui* rmd = (gui*)mParent;
rmd->LeftPanelActivate(false);
rmd->SetNewPositions(rmd->GetParent()->GetSize());
Button::Update();
helper::SendRedrawEvent(mParent);
DoAction = false; // indicates action activated
}
}
and function that calls SetValue()
void AddButton::OnEnter(wxCommandEvent& event)//enter button handler
{
wxTextCtrl* _t = (wxTextCtrl*)this;
_Clear();
*_t<<"sup";
}
I think you have a problem with understanding of Connect(). If you're using it to connect to a method of a different object, you must pass a pointer to this object as the last argument (called eventSink in the documentation). Your method is almost certainly being called on a wrong object pointer.
And you should absolutely never, ever have to cast this like you do in OnEnter().
Are you sure that you really need to delete the wxTextCtrl? If this text control is placed into sizer then sizer is responsible for it and will destroy it when needed. You probably need to detach the text control from sizer and then delete it.
Also you should use Destroy() method instead of delete operator. This is clearly explained in docs.
As for crash on SetValue() call: have you tried to use wxT("abc")? Also what version of wxWidgets, OS and compiler are you using? Haven't experienced such problems with wxWidgets at all. Maybe you could post some meaningful piece of code which can help to identify the problem?
I'm trying to have animation on a button click event. But somehow the animation is not working. I have referred the Qt reference docs, but could not find the root cause which is causing the issue
Below is sample code :
void MainWindow::AnimationClick()
{
// define toolbar y movement positions for animation
TOOLBAR_Y_SHOWN = 0;
TOOLBAR_Y_HIDDEN = -m_AnimatedWidget->height();
m_AnimatedWidget = new AnimatedWidget(this);
QPropertyAnimation *m_ani = new QPropertyAnimation(m_AnimatedWidget, "pos", this);
m_ani->setDuration(500);
m_ani->setEndValue(QPoint(m_AnimatedWidget->pos().x(), TOOLBAR_Y_HIDDEN));
m_ani->setEasingCurve(QEasingCurve::InBack);
m_ani->start();
}
With the above implementation nothing is happening on the click event.
Any suggestions , Thanks.
This looks wrong:
TOOLBAR_Y_HIDDEN = -m_AnimatedWidget->height();
m_AnimatedWidget = new AnimatedWidget(this);
First you access m_AnimatedWidget then you allocate it?
When you get a crash, such as segmentation fault, always run your program in a debugger. It would have helped you find this error quite easy as it would have stopped on the line of the error.
m_ani->setDuration(500);
setDuration() argument is expressed in milliseconds. You should probably put more than half a second when you are testing.
I got it. I was not allowing the m_AnimatedWidget to show upon the screen.
Below is the edited snippet.
void MainWindow::AnimationClick()
{
// define toolbar y movement positions for animation
TOOLBAR_Y_SHOWN = 0;
m_AnimatedWidget = new AnimatedWidget(this);
TOOLBAR_Y_HIDDEN = -m_AnimatedWidget->height();
QPropertyAnimation *m_ani = new QPropertyAnimation(m_AnimatedWidget, "pos", this);
m_ani->setDuration(5000);
m_ani->setEndValue(QPoint(m_AnimatedWidget->pos().x(), TOOLBAR_Y_HIDDEN));
m_ani->setEasingCurve(QEasingCurve::InBack);
m_ani->start();
m_AnimatedWidget->show();
}
I face a very serious situation. By writing this question I hope that really professionals will express their opinion regarding to the problem I am going to describe. I have reported a bug in https://bugreports.qt.io/ :
I have created QPropertyAnimation for maximumWidth property of QTextEdit and it does not work (it immediately changes state from starting state to the end state), though it works for minimumWidth property.
Please see the attached code.
And have attached .h and .cpp files. See those files here (files are named new.h and new.cpp).
And I got the follwing response:
MaximumWidth is not the property you want to animate. It holds the maximum width that the widget can have, it's related to layouting and so on. Changing the maximumWidth (as well as the minimumWidth) does not necessarily trigger a relayout and repaint. You should animate the size.
Please explain me whether it is a bug or no? Please tell me how the minimumWith property is being animated but when it concerns to the maximumWidth property, then I should not work and that is OK? I just don't get their point... Please explain.
P.S. I have written this code because I wanted to close by animation the right QTextEdit and be sure that when I resize the main window, where the button and two QTextEdit are, the closed QTextEdit does not being restored.
Did you check the actual value of maximumWidth? You don't seem to set a specific maximumWidth in your code.
The default value for maximumWidth is 16777215, and you set a duration of 1 msec. for the closing animation. Fading from 16777215 to 3 in 1 msec. would look like "instant", I guess.
I don't think it is a bug; I'd call it "undefined behavior". That means that if you try to animate minimumWidth, nobody can tell you for sure what is supposed to happen, and maybe the code has some optimizations or corner cases where sometimes it works, others it doesn't.
Anyway, minimumWidth and maximumWidth aren't supposed to be used to define what the size of a QWidget is, only what it must not exceed; i.e. they weren't designed to do what you are trying to do, so it can be called a bug. If you want to animate, you have to use a deterministic approach, which in this case is using the geometry property.
This is not a bug, the response you got from the bug report pretty well explains the problem with your code and a solution.
Dear Sofahamster I have changed my code to the code below and it works fine. Thanks for your hint!
Header file
class MyWidget : public QWidget
{
Q_OBJECT
QTextEdit *m_textEditor1;
QTextEdit *m_textEditor2;
QPushButton *m_pushButton;
QHBoxLayout *m_layout;
QVBoxLayout *m_buttonLayout;
int m_deltaX;
bool m_isClosed;
public:
MyWidget(QWidget * parent = 0);
~MyWidget(){}
void resizeEvent( QResizeEvent * event );
private slots:
void closeOrOpenTextEdit2(bool isClosing);
};
Source file
MyWidget::MyWidget(QWidget * parent):QWidget(parent),m_deltaX(0)
{
m_pushButton = new QPushButton(this);
m_pushButton->setText(">");
m_pushButton->setCheckable(true);
m_pushButton->setFixedSize(16,16);
connect(m_pushButton, SIGNAL(clicked(bool)), this, SLOT(closeOrOpenTextEdit2(bool)));
m_textEditor1 = new QTextEdit(this);
m_textEditor1->setText("AAAAA AAAAAAAAAAA AAAAAAAAAAA AAAAAAA AAAAAAAAAAA AAAAAAAAAAA AA");
m_textEditor2 = new QTextEdit(this);
m_buttonLayout = new QVBoxLayout();
m_buttonLayout->addWidget(m_pushButton);
m_buttonLayout->addItem( new QSpacerItem(1, 1, QSizePolicy::Minimum, QSizePolicy::Expanding) );
m_layout = new QHBoxLayout;
m_layout->addWidget(m_textEditor1, 10);
m_layout->addSpacing(15);
m_layout->addLayout(m_buttonLayout);
m_layout->setSpacing(0);
m_layout->addWidget(m_textEditor2, 4);
setLayout(m_layout);
resize(800,500);
}
void MyWidget::closeOrOpenTextEdit2(bool isClosing)
{
m_isClosed = isClosing;
QPropertyAnimation *animation1 = new QPropertyAnimation(m_textEditor2, "maximumWidth");
if(isClosing) //close the second textEdit
{
m_textEditor2->setMaximumWidth(m_textEditor2->width());
int textEdit2_start = m_textEditor2->maximumWidth();
m_deltaX = textEdit2_start;
int textEdit2_end = 3;
animation1->setDuration(500);
animation1->setStartValue(textEdit2_start);
animation1->setEndValue(textEdit2_end);
m_pushButton->setText("<");
}
else //open
{
int textEdit2_start = m_textEditor2->maximumWidth();
int textEdit2_end = m_deltaX;
animation1->setDuration(500);
animation1->setStartValue(textEdit2_start);
animation1->setEndValue(textEdit2_end);
m_pushButton->setText(">");
}
animation1->start();
}
void MyWidget::resizeEvent( QResizeEvent * event )
{
if(!m_isClosed)
m_textEditor2->setMaximumWidth( QWIDGETSIZE_MAX );
}