0

Recently started doing some programming for Windows and I simply can't get my program to work. I am trying to achieve an environment in which I mainly can use HTML for the frontend and control the backend with Javascript. On Linux I've managed to add functions and stuff to the "JavaScriptCore" but Windows haven't been to kind with me.

Currently I'm trying to catch the URL change event, allowing for special URLs to execute commands, however I get the following error:

error: C2664: 'connect' : cannot convert parameter 1 from 'QWebView *' to 'SOCKET'
There is no context in which this conversion is possible

I didn't manage to find a single search result concerning "QWebView to SOCKET" so I have no clue what to do but to ask you guys.

Here is my code. I'm not too good with programming to please be gentle ;)

#include <QtGui>
#include <QtWebKit>
#include <QApplication>
#include <QWebView>
#include <iostream>

using namespace std;

void test()
{
    cout << "Hello world";
}

int main(int argc, char** argv) {
    QApplication app(argc, argv);
    QWebView view;
    view.setWindowFlags(Qt::CustomizeWindowHint);
    view.setWindowFlags(Qt::FramelessWindowHint);
    view.setFixedSize(1000,600);
    view.setStyleSheet("background:transparent;");
    view.setAttribute(Qt::WA_TranslucentBackground);
    view.setUrl(QUrl("http://google.com"));
    view.setWindowTitle("test v0.1");
    connect(view, SIGNAL(urlChanged(QUrl)), SLOT(test()));
    view.show();

    return app.exec();
}
Xweque
  • 605
  • 1
  • 9
  • 29
  • Your void test() does not look like a slot method in a QObject derived class. Qt would not create connection metadata for this. Also, the signatures of signal and slot functions must match. – DNT Nov 08 '14 at 21:42
  • 2
    @DNT - I think the excess signal parameters simply get discarded when connecting to a function that accepts less parameters. – dtech Nov 08 '14 at 21:51
  • One more thing: the error message clearly indicates that the connect call, is interpreted as a call to the networking socket connect function, and not the one from Qt you intended to call. – DNT Nov 08 '14 at 21:51
  • @ddriver Whenever I made a typo, writing mismatched signatures I got an error from QObject::connect, and no connection occurred (Qt 4.7.1). According to docs the parameter types must be specified and must be the same in signal and slot specifications within the QObject::connect call. Did not get to Qt 5.x yet, so I defer to you for that. – DNT Nov 08 '14 at 21:55
  • 2
    @DNT - from Qt 4.7 DOC "The signals and slots mechanism is type safe: The signature of a signal must match the signature of the receiving slot. (In fact a slot may have a shorter signature than the signal it receives because it can ignore extra arguments.)" You didn't get connection because it was a typo, not because signatures were not perfect match. – dtech Nov 08 '14 at 21:59

1 Answers1

2

Try this instead:

QObject::connect(&view, &QWebView::urlChanged, test);

You are using the old connection syntax which works only with QObjects and slots, test is not a slot and it is not a function of a QObject derived class, it is a free funciton, so you have to use the new syntax, available since Qt 5.

When you are not inside a QObject you don't have access to connect(), that is why my example uses the QObject namespace to invoke it in main(). In your case as DNT noted it is just some other function that happens to be named "connect".

Another mistake you made is you passed the view, but connect() works with pointers, so you have to use the & operator to get a pointer to the view.

dtech
  • 47,916
  • 17
  • 112
  • 190
  • About connection problem also see http://stackoverflow.com/questions/26422154/my-slot-is-not-invoked-called-used-working-executed – Silicomancer Nov 08 '14 at 22:34