Need help converting 6 year old app to new coding

Hi Guys…

I need help to be able to compile an app in newer xcode…
i have changed already ScopedPointer for std::unique_ptr

But this breaks my app… i hope someone could assist me in this… ))

Kind regards…

ScopedPointer is marked deprecated, but afaik, it should still function Ok in the latest version of JUCE? I’m not 100%, but I’m almost certain I have a few ScopedPointer’s lying around the place in one of my projects, and it’s building fine with JUCE6.

With regards to your crash, it’s not possible to say without seeing the backtrace, or some code.

Hi Rory…

At first my app was build with JUCE 5.4.3 and xcode what came with osx mavericks ( or so )

now i have Catalina running and xcode v12.4 and projucer 6.1.2 and i am using the old scripts i created over 5 years ago…
this now gives me all kinds of errors in xcode and would not compile… one of the errors was that i could not use ScopedPointer… so in all my scripts i have changed this to Std::unique_ptr
Witch now created a whole lot of other issues… and i am not really a programmer and wish someone could help me get arround these problems… can even give acces to my computer…

One of the errors i get now ( a Lot 25 times ) is : No viable overloaded ‘=’ when calling : componentCommandManager = new ApplicationCommandManager();

Kind regards

Assuming that componentCommandManager is a std::unique_ptr<ApplicationCommandManager>:

You can not assign a raw pointer to a managed pointer. There are two ways to do this with unique_ptr:

  1. create a unique_ptr using make_unique and assign it:
componentCommandManager = std::make_unique<ApplicationCommandManager>();
  1. call reset to set the unique_ptr to point to the raw pointer:
componentCommandManager.reset (new ApplicationCommandManager());

There are plenty old threads from when the change happened where most of these questions were answered, maybe give the forum search a go.

Here is the documentation of std::unique_ptr. Check also the Examples there.

1 Like

componentCommandManager = std::make_unique < ApplicationCommandManager>();
for this line it worked … so far no error…
but i have manny others where i cannot get this to work… example :
addAndMakeVisible(groupComponent = new GroupComponent (“new group”, “Profiles”));
and simulair :
addAndMakeVisible(selectButton = new TextButton (“profiles”));

Kind regards…

Yes, this is no longer possible in one line. Instead you need to write:

selectButton = std::make_unique<TextButton>(“profiles”);
addAndMakeVisible (selectButton.get());

I know, it’s a tedious task, but it was necessary, because using the unique_ptr is safer than the old ScopedPointer (because of all those implicit conversions, they were too convenient).

okay i copied your solution…
Had to change a litle.
//addAndMakeVisible(selectButton = new TextButton (“profiles”)); <=== old
selectButton = std::make_unique < TextButton>(“profiles”);
addAndMakeVisible (selectButton.get());

thank you… ))

Well i am ajusting a lot of the coding but it creates only more and more errors… even while the script what i am editting starts to look better…

al lot of these errors i get now :
/Users/oscar/Desktop/APB-3243/Source/ProfilesWindow.cpp:235:32: Invalid operands to binary expression (‘juce::Button *’ and ‘std::unique_ptr’)
wich i do not understand… ((

Typing “scopedpointer unique_ptr” in the forum search gave this first hit:

To compare a button e.g. in a Button::Listener you need to get the raw pointer using .get():

if (buttonThatWasClicked == myButton.get())
    // do whatever

Alright … i am down to only 2 errors )))

1 : Image dragImage = Image::null, Where null is not accepted anymore and i have no clue how to fix that too…
2 : setContentOwned(profilesManager, true ); gives :
No viable conversion from ‘std::unique_ptr’ to ‘juce::Component *’
when these two are solved i should be able to compile again ))

thank you so so much for your time and usable hints…
and ofcourse i am looking all over the forum… but i have been reading the last 5 days… as my app also has an node problem with expired CA… ( tried all tricks for that but with no good outcome yet )

No worries, I am happy to give you those two as well:

  1. The static Image::null was removed. Instead you can simply check dragImage.isValid() or dragImage.isNull(). And no need to assign anything, Image() will return an empty / invalid image.
  2. setContentOwned (profilesManager.get(), true );

Cheers

Okay Nr 2 is working Jeeey…!!! ))
Nr 1 : dragImage.isNull() gives error Expected ‘)’
tried both your solutions but these both comes with an error…

We need to see the code, the error points to a simple mismatch of brackets…

okay… i dont mind to send the code but where to send it… ?

void startDragging( const var& sourceDescription,

Component* sourceComponent,

//Image dragImage = Image::null,

//Image dragImage.isValid()

dragImage.isNull()

bool allowDraggingToOtherJuceWindows = false ,

const Point< int >* imageOffsetFromMouse = nullptr

Ok, I see…
This method is not virtual btw. so overriding is not really possible.
But if you look up the docs you see the current signature:

void DragAndDropContainer::startDragging 	( 	const var &  	sourceDescription,
		Component *  	sourceComponent,
		Image  	dragImage = Image(),
		bool  	allowDraggingToOtherJuceWindows = false,
		const Point< int > *  	imageOffsetFromMouse = nullptr,
		const MouseInputSource *  	inputSourceCausingDrag = nullptr 
	)

The Image::null was a static dummy. Instead you call now the default constructor to get an invalid Image (like I said before).

Hi Daniel… sorry for the late reply… it was already 2 am my time… had to get some sleep… ))

that part is also solved… xcode then did not show any errors… untill i started to build…

had to put a lot .get() in place… now i only have 2 more errors… and not sure what to do with that.
const int result = m.showMenu(PopupMenu::Options().withTargetComponent(extrasButton));
come with error :
No member named ‘showMenu’ in ‘juce::PopupMenu’
i think we are verry close…
and sorry for my stupid questions… i just started to learn all this ))

That one is from a breaking change in 6.1. Please follow this thread: