[C++] SListView problem!

Hello.
I want to create SList with FStrings inside. Thats what I have:

Header:

TSharedRef<ITableRow> OnGenerateRowForList(TSharedPtr<FString> InItem, const TSharedRef<STableViewBase>& OwnerTable);

TSharedRef<class SDockTab> OnSpawnPluginTab(const class FSpawnTabArgs& SpawnTabArgs);
/* The list of strings */
TArray<TSharedPtr<FString>> Items;

/* The actual UI list */
TSharedPtr< SListView< TSharedPtr<FString> > > ListViewWidget;

Source:

TSharedRef<ITableRow> FAdvancedDialoguesModule::OnGenerateRowForList(TSharedPtr<FString> InItem, const TSharedRef<STableViewBase>& OwnerTable)
{ 
	//Create the row
	return
		SNew(STableRow< TSharedPtr<FString> >, OwnerTable)
		.Padding(2.0f)
		[
			SNew(STextBlock).Text(*InItem.Get())
		];
}
...
[
SAssignNew(ListViewWidget, SListView<TSharedPtr<FString>>)
	.ItemHeight(24)
	.SelectionMode(ESelectionMode::Single)
	.ListItemsSource(&Items) //The Items array is the source of this listview
	.OnGenerateRow(this,&FAdvancedDialoguesModule::OnGenerateRowForList)
]

But when I try to compile:

C:\Program Files\Unreal Engine\4.12\Engine\Source\Runtime\Core\Public\Misc\Attribute.h(44): error C2248: 'FText::FText': cannot access private member declared in class 'FText'
1>  c:\program files\unreal engine\4.12\engine\source\runtime\core\public\internationalization\Text.h(371): note: see declaration of 'FText::FText'
1>  c:\program files\unreal engine\4.12\engine\source\runtime\core\public\internationalization\Text.h(139): note: see declaration of 'FText'
1>  C:\Users\Hubert\Documents\Unreal Projects\RFG1 4.12\Plugins\AdvancedDialogues\Source\AdvancedDialogues\Private\AdvancedDialogues.cpp(66): note: see reference to function template instantiation 'TAttribute<FText>::TAttribute<ObjectType>(const OtherType &)' being compiled
1>          with
1>          [
1>              ObjectType=FString,
1>              OtherType=FString
1>          ]
1>  C:\Users\Hubert\Documents\Unreal Projects\RFG1 4.12\Plugins\AdvancedDialogues\Source\AdvancedDialogues\Private\AdvancedDialogues.cpp(62): note: see reference to function template instantiation 'TAttribute<FText>::TAttribute<ObjectType>(const OtherType &)' being compiled
1>          with
1>          [
1>              ObjectType=FString,
1>              OtherType=FString
1>          ]

Can some help/exaplain whats wrong with this code?

Regards,

HRZ

Use of FString is depricated in most of the slate, use FText insted.

FString in not problem here. I noticed that when I comment out //.OnGenerateRow(this, &FAdvancedDialoguesModule::OnGenerateRowForList)
everything is working fine.

I got a same problem,have you work it out?

Change

SNew(STextBlock).Text(*InItem.Get())

to

SNew(STextBlock).Text(FText::FromString(*InItem))

… but then another problem occurs. It seems that delegates does not support AsShared() function.

Maybe insted of array of text names, use array of those item objects and read text from it, i notice that common practice in editor with SListView. Note text it self can be static don’t need to give delegates or pointers to slate, all you need to do is reconstruct the list on any array change

I don’t know if you still have this issue, anyway it can be useful for other people, i got this problem too and the solution is really really simple :

Just replace

.OnGenerateRow

by

OnGenerateRow_Raw
1 Like