Like Dialog in facebook android sdk is closed immediately - facebook-like

I'm using Facebook Android SDK (3.19) in my app and following this link https://developers.facebook.com/docs/android/like-button to use Like Button. When I clicked like button, Like Dialog was shown and dismissed immediately. Also, onActivityResult was not called. I don't know why. Please somebody help me to fix this. Thanks.
Edit: My code
public class ContentFragment extends Fragment{
LikeView likeView;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRetainInstance(true);
Settings.sdkInitialize(getActivity());
Settings.setPlatformCompatibilityEnabled(false);
Settings.setIsDebugEnabled(true);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = LayoutInflater.from(getActivity()).inflate(R.layout.content_fragment, null);
likeView = (LikeView) view.findViewById(R.id.like_view);
likeView.setObjectId("http://shareitexampleapp.parseapp.com/photo1/");
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
LikeView.handleOnActivityResult(getActivity(), requestCode, resultCode, data);
Toast.makeText(getActivity(), "onActivityResult", Toast.LENGTH_SHORT).show();
}
}
Edit2: CLOSED. It's my mistake. My test account was not added to my facebook app's testers. Thanks.

Related

Hide Application when outside the desktop application is clicked

I made an utility/tray application using flutter and i want it to hide when i click outside the application. How can we do this? I researched quite some time but i could not get the answer to this.
I looked out for window_manager, bitsdojo, googling, youtube and documentation. But could not get the answers.
You can use window_manager, which helps to find the focus.
import 'package:flutter/cupertino.dart';
import 'package:window_manager/window_manager.dart';
class HomePage extends StatefulWidget {
#override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> with WindowListener {
#override
void initState() {
windowManager.addListener(this);
super.initState();
}
#override
void dispose() {
windowManager.removeListener(this);
super.dispose();
}
#override
Widget build(BuildContext context) {
// ...
}
#override
void onWindowFocus() {
// do something when app gets into focus state
}
#override
void onWindowBlur() {
// do something when app gets into inactive/blur state
}
}

Trying to write an "Observer" pattern

Did I correctly implement this pattern? The idea of my example is that there are document and application (app performs an observer role). At the beginning each document should attach the observer. Further, document could close all documents except himself by emitting a signal to observer (application).
Requirement - example should use an event model.
class Application
{
std::vector<Document *> docs;
public:
void add_document(Document *doc)
{
docs.push_back(doc);
}
public slots:
void close_non_active_docs_button_pressed(Document *active_doc)
{
for (auto idoc: this->docs)
{
if (idoc == active_doc)
continue;
idoc->close();
}
}
}
class Document
{
Application *app;
public:
void attach_to_app(Application *app)
{
this->curr_app = app;
app->add_document(this);
}
void close(){...};
public signals:
void close_non_active_docs_button_pressed(Document *active_doc);
...
emit close_non_active_docs_button_pressed(this);
}
///CONNECT(...)

How to use QWebEnginePage::OpenLinkInNewTab [Qt5.8]

When I click on link to any question in my feed on Quora using this code, the link doesn't open but it doesn't print "Hello". Could you please tell me where am I wrong? I'm pretty sure that link on quora emits the OpenLinkInNewTab signal. Please help, thanks.
class WebView : public QObject {
void newTabRequested() {
std::cout<<"Hello"<<std::endl;
}
public:
char* home_page;
QAction* newTabAction=new QAction();
QWebEngineView* view=new QWebEngineView();
WebView(char* page=(char*)"https://google.com") {
this->home_page=page;
this->exitFullScreen->setShortcut(Qt::Key_Escape);
createWebView();
this->view->settings()
->setAttribute(QWebEngineSettings::JavascriptCanOpenWindows,true);
this->newTabAction=this->view->pageAction(QWebEnginePage::OpenLinkInNewTab);
connect(this->newTabAction,&QAction::toggled,this,&WebView::newTabRequested);
}
void createWebView() {
this->view->load(QUrl(this->home_page));
}
};
I think the problem is that newTabRequested is not a slot. Try
class WebView : public QObject{
Q_OBJECT
private slots:
void newTabRequested(){
std::cout<<"Hello"<<std::endl;
}
// ...
}

How to emulate linkClicked(QUrl) signal in QWebEngineView?

I am porting my project from Qt WebKit to Qt WebEngine in Qt5.6. I want to emit linkClicked(QUrl) signal when a href is clicked on the QWebView, but QWebEngineView has no signal linkClicked(QUrl).
How to emulate linkClickedSignal(QUrl)?
Porting from Qt WebKit to Qt WebEngine.
Thank you #Alexis P. I have got it.
class MyWebPage : public QWebEnginePage
{
Q_OBJECT
public:
MyWebPage(QObject* parent = 0) : QWebEnginePage(parent){}
bool acceptNavigationRequest(const QUrl & url, QWebEnginePage::NavigationType type, bool)
{
if (type == QWebEnginePage::NavigationTypeLinkClicked)
{
//QDesktopServices::openUrl(url);
emit linkClicked(url);
return false;
}
return true;
}
signals:
void linkClicked(const QUrl&);
};
In my window class:
webView = new QWebEngineView(ui->verticalLayoutWidget);
webView->setPage(new MyWebPage());
ui->verticalLayout->addWidget(webView);
connect(webView- >page(),SIGNAL(linkClicked(QUrl)),this,SLOT(linkClicked(QUrl)));
I am not sure it will be useful for you, but in my app using QWebEngineView, I have clickable links which must open the corresponding website in a browser.
The way I am doing it is like that :
class MyQWebEnginePage : public QWebEnginePage
{
Q_OBJECT
public:
MyQWebEnginePage(QObject* parent = 0) : QWebEnginePage(parent){}
bool acceptNavigationRequest(const QUrl & url, QWebEnginePage::NavigationType type, bool)
{
if (type == QWebEnginePage::NavigationTypeLinkClicked)
{
QDesktopServices::openUrl(url);
return false;
}
return true;
}
};
As you can see, I just reimplemented the virtual method acceptNavigationRequest of QWebEnginePage in order to retrieve the url from the link clicked : url. I don't know it is what you want to achieve, but I hope that helps.

Is there in Qt forms onChange event?

Is there in Qt something like Form.onChange in Delphi?
I found some changeEvent method but when I wrote connect
connect(this, SIGNAL(this->changeEvent),this, SLOT(checkIfSomethingChanged()));
and tried to check it like that
void importdb_module::checkIfSomethingChanged(){
QMessageBox::information(0, "", "Test");
}
I realized that it not works.
I want to check some condition everytime when something changed in my form, how to do that?
The changeEvent slot is a virtual, protected function found in QWidget. Therefore, if you inherit from QWidget or any QWidget derived class, you'll be able to override that function. For example: -
class MyForm : public QWidget
{
protected slots:
virtual void changeEvent(QEvent * event);
}
void MyForm::changeEvent(QEvent* event)
{
// Do something with the event
}
If you wanted to know outside of the event that the form has been changed, you can add a signal to the form and emit it from the changeEvent to pass the event on: -
class MyForm : public QWidget
{
signals:
void FormChanged(QEvent* event);
protected slots:
virtual void changeEvent(QEvent * event);
}
void MyForm::changeEvent(QEvent* event)
{
emit FormChanged(event);
}
Now connect another class to the new signal, using Qt 5 connect syntax: -
connect(myFormObject, &MyForm::FormChanged, someclassObject, &SomeClass::HandleFormChanged);
This cannot work, because you mixed up two concepts: events and signal/slots. To make it work, you need to override your class' changeEvent() virtual function. Something like this:
void MyWidget::changeEvent(QEvent *event)
{
QMessageBox::information(0, "", "Test");
}