x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

ListView dynamic update

Friends! Tell me why, when you try to update the text in the list, an error occurs . I created a project on github. https://github.com/Luummii/listunreal

I guess I don't know anything. Really need help.

After starting the project, there will be a button on the screen. When you click on the button, a list with the text in each line should appear. The text is put in C++.

But instead, a list with the initial text set to BP appears and an error falls out.

I tried to understand and it turns out that the list item is not created at the time of installation of the text. But for what reason remains a mystery to me.

Look please, if not difficult, where there is a mistake.

Error occurs when calling the method void UListComponent_CPP::SetActionName(FString TaskName)

and it happens because there is ensureMsgf(...). But if you disable ensureMsgf, the Studio falls.

It crashes because the TextBlock_ActionName pointer is undefined. And very strange!!! For me:)

If the method implementation void UListComponent_CPP::SetActionName(FString TaskName)

move to the constructor - set the text in the constructor, then there is no error and everything works well.

Please explain where am I wrong?

Product Version: UE 4.22
Tags:
more ▼

asked May 18 '19 at 11:51 AM in C++ Programming

avatar image

Luummii
1 1 2

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

you not created instance of TextBlock_ActionName.

execute this code an UListComponent_CPP class function.

TextBlock_ActionName = WidgetTree->ConstructWidget(UTextBlock::StaticClass(), "example");

more ▼

answered May 20 '19 at 01:36 PM

avatar image

sc-stsubasa
1 1 1

avatar image Luummii May 20 '19 at 03:56 PM

Frend! The instance TextBlock_ActionName is created by this line UPROPERTY(BlueprintReadWrite, meta = (BindWidget))

avatar image sc-stsubasa May 21 '19 at 02:32 AM

I did not know how. Thank you very much.

The list view item is generated when it enters the drawing area by scrolling or the like.

You must bind "OnEntryGenerated" or implement UListView by inheriting "UListView :: OnGenerateEntryWidgetInternal ()".

avatar image Luummii May 21 '19 at 09:38 AM

Have you tried cloning a project and doing what offers? :)

avatar image Unknown_PG May 21 '19 at 12:47 PM

i am sc-stsubasa.from private account

I'm sorry. I was thinking too hard. Please try the changes below.

 //--------------------------------
 class UListComponent_CPP
 {
   //    add
   FText MyTaskName;
     
 }
 //--------------------------------
 void UListComponent_CPP::NativeConstruct()
 
 {
   Super::NativeConstruct();
   // add
   TextBlock_ActionName->SetText(MyTaskName);
 }
 
 //--------------------------------
 void UListComponent_CPP::SetActionName(FString TaskName)
 
 {
 #if true
     MyTaskName = FText::FromString(TaskName);
 #else
   if (ensureMsgf(TextBlock_ActionName, TEXT("TextBlock_ActionName is invalid")))
 
     TextBlock_ActionName->SetText(FText::FromString(TaskName));
 #endif
 
 }
 //--------------------------------
avatar image Luummii May 21 '19 at 04:40 PM

My answer hasn't changed - Have you tried cloning a project and doing what offers? :)))

avatar image sc-stsubasa May 22 '19 at 01:22 AM

I copied your project and confirmed it.

Excuse me, do you understand that the time when the list view item is generated as a widget and NativeConstruct is called is when it enters the display area?

avatar image Luummii May 22 '19 at 06:15 AM

Oh, my friend, forgive me. Maybe you can solve this problem then. Could you then make a push of code with a working example? The thing is that I tried to update the text in the list at different times of widget generation and yet the quest is not completed. :))

avatar image sc-stsubasa May 22 '19 at 10:30 AM

I checked a little, but ListView did something strange.

You can see that creating a constructor for UListComponent_CPP and setting a breakpoint It seems that a completely new UListComponent_CPP is being generated instead of using the one set when entering the area.

※ Confirmed by the following constructor

 UListComponent_CPP :: UListComponent_CPP (const FObjectInitializer & ObjectInitializer)
 : Super (ObjectInitializer)
 {
 }

The following code is generated

 ListViewBase.h (471)
 WidgetEntryT & GenerateTypedEntry (TSubclassOf  WidgetClass, const TSharedRef  & OwnerTable);

OnEntryGenerated bound to the blueprint graph only passed the object generated above. The rough calling order is as follows, so it may be better to look a little.

 UListViewBase :: GenerateTypedEntry ()
 UListViewBase :: FinishGeneratingEntry ()
 UListViewBase :: HandleAnnounceGeneratedEntries ()
 UListViewBase :: BP_OnEntryGenerated.Broadcast (EntryWidget.Get ());

The only way to think of it now is to inherit UListView and override OnGenerateEntryWidgetInternal () ...

avatar image Luummii May 23 '19 at 06:27 AM

Very strange! A simple task - When you click on the button, update the list item. The update logic must be in C++. Asked this task here, in Discordchats in two channels, sent questions to youtubers who clever lessons do. No answer. Not who does not know how to work with it. Only simple General advice and remark - need to do so and so and so. And when you ask a question - You tried to realize your advice? - going oops...:)) Sorry, mate! Thank you for your help! You held out the longest:))

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question