Download

Can someone give me code snippet of how to use TFunction?

FWebBrowserWindow::GetSource(TFunction<void(const FString&)> Callback) const;

I need to use GetSource to get html content, does anyone know how to input a correct TFunction ?

Thanks. :frowning:

TFunctions are just lambdas.




// To a class method:
void ProcessSource(const FString& content)
{
  // Do stuff.
}

//...
TFunction<void(const FString&)> MyProcessFunction = &ProcessSource;

MyWebBrowserWidget.GetSource(MyProcessFunction);

// As an inline function / lambda
TFunction<void(const FString&> MyProcessFunction = &](const FString& content){ // Do stuff};
MyWebBrowserWidget.GetSource(MyProcessFunction);


Late to the party but for future references and if someone stumbles on to this one

DECLARE_LOG_CATEGORY_EXTERN(LogBrowserVerbose, Verbose, All);
/**
 * Extending UE4's Web Browser component to add up page source functionality
 * Makes use of WebBrowserWidget
 */
UCLASS()
class EXTENDEDBROWSER_API UExtendedBrowser : public UWebBrowser
{
	GENERATED_BODY()
public:
	class SWebBrowser;
	/** Gets called after extracting Page Source */
	UFUNCTION(BlueprintCallable)
	void ProcessSource(const FString& content) {}
	/** Widget event for extended browser gets called automatically when GetPageSource() returns*/
	UPROPERTY(BlueprintAssignable, Category = "PageSource")
	FBrowserSourceDelegate OnPageSource;
	/**
	 * BlueprintCallable Asynchronous Page Source function
	 * Asynchronously calls OnPageSource and Process Source with contents of page 
	 */
	UFUNCTION(BlueprintCallable)
	void GetPageSource()
	{
		TFunction<void(const FString& content)>fp = [this](const FString& content) {
		ProcessSource(content);
		OnPageSource.Broadcast(content);
		PRINTLOG(LogBrowserVerbose,content);
		};
		WebBrowserWidget->GetSource(fp);
	}

};
UCLASS()
class EXTENDEDBROWSER_API ULoginBrowserUI : public UUserWidget
{
	GENERATED_BODY()

public:
	/** Extended Web Browser Widget with functionality to get page source */
	UPROPERTY(EditAnywhere,BlueprintReadWrite,meta = (BindWidget))
	UExtendedBrowser* WebbrowserComp;
public:
	void NativeConstruct() override;
	/** OnSucessful FBLogin Delegate */
	UPROPERTY(BlueprintAssignable, BlueprintCallable)
	FBrowserSourceDelegate OnPageSource;
};
1 Like