Link error with Qt5 webkit - qt-creator

I want to make a browser in qt5 using qtwebkit but I found some error when I get download my site. I don't know the reason. I added the webkit library, and call it in mainwindow.h:
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QtWebKit/QtWebKit>
namespace Ui { class MainWindow; }
class MainWindow : public QMainWindow {
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private slots:
void on_pushButton_clicked();
void on_pushButton_2_clicked();
void on_pushButton_3_clicked();
void on_pushButton_4_clicked();
private:
Ui::MainWindow *ui; };
#endif // MAINWINDOW_H
mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
ui->webView->back();
}
void MainWindow::on_pushButton_2_clicked()
{
ui->webView->forward();
}
void MainWindow::on_pushButton_3_clicked()
{
ui->webView->reload();
}
void MainWindow::on_pushButton_4_clicked()
{
ui->webView->load("http://" + ui->lineEdit->text());
}
and this when i called library
#-------------------------------------------------
#
# Project created by QtCreator 2013-10-31T07:39:06
#
#-------------------------------------------------
QT += core gui QT += webkit
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = mozilabrwser TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
I tried to change the name of webkit but I still get this error:
D:\ubunto\QT5\Tools\QtCreator\bin\mozilabrwser\mainwindow.cpp:19: error:
undefined reference to `_imp___ZN8QWebView4backEv'

QT += core gui QT += webkit
is wrong. You seem to be using Qt 5, and in Qt 5 the correct module is webkitwidgets. 2nd issue is format, you seem to have two lines concatenated. So this should work:
QT += core gui
QT += webkitwidgets
Note: If you need to have the program compile with both Qt4 and Qt5, then you need to use conditional, adding webkit for Qt4, webkitwidgets for Qt5. But this is probably not a concern for a hobby project, no point clutteirng the .pro file with that stuff until you actually need it (you will also need some source changes and #ifdef stuff in code if you want to support both, so don't go there unless it is an important requirement).
Same two lines concatenated issue seems to be also in line TARGET = mozilabrwser TEMPLATE = app.

Related

Opencv program using qtcreator undefined reference in ubuntu for imread or any string

include "mainwindow.h"
include "ui_mainwindow.h"
include <opencv2/opencv.hpp>
using namespace cv;
using namespace std;
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
cv::Mat inputImage = cv::imread("/home/chaiein/VR/1.jpg");
cv::imshow("Display Image", inputImage);
}
MainWindow::~MainWindow()
{
delete ui;
}
Error
/home/chaiein/VR/linePose/mainwindow.cpp:11: error: undefined reference to `cv::imread(std::__cxx11::basic_string, std::allocator > const&, int)'
My linepose.pro file as the following content
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = linePose
TEMPLATE = app
INCLUDEPATH += /usr/local/include/opencv /opt/ros/kinetic/share/OpenCV-
3.2.0-dev
LIBS += -L/usr/local/lib -lopencv_core -lopencv_imgcodecs -lopencv_highgui
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
I have searched in many links but this problem seems to have different solution please help me!!

How to detect screen lock (Qt5, C++, Windows, OSX)

In my Qt5 C++ client, I'm wanting to detect when a user running Windows or OSX has locked the screen, then simultaneously lock my client application.
I have yet to come across a Qt5 class that provides this function, so I'm wondering if I'll need to write an OS-specific library. Does anyone have any experience doing something like this?
Thanks!
On windows you can use below code:
mywidget.cpp
#include "mywidget.h"
#include <Windows.h>
#include <WtsApi32.h>
#include <QDebug>
MyWidget::MyWidget(QWidget *parent) : QWidget(parent)
{
WTSRegisterSessionNotification((HWND)this->winId(), NOTIFY_FOR_THIS_SESSION);
}
MyWidget::~MyWidget()
{
WTSUnRegisterSessionNotification((HWND)this->winId());
}
bool MyWidget::nativeEvent(const QByteArray &eventType, void *message, long *result)
{
if (eventType != "windows_generic_MSG") return false;
MSG *msg = static_cast<MSG*>(message);
switch (msg->message) {
case WM_WTSSESSION_CHANGE:
qDebug() << "session change: " << msg->wParam;
}
return false;
}
project.pro
...
LIBS += -lwtsapi32
...
reference1
reference2

Why create MFC dialog wizard not includes resources.h

I have created MFC dialog form resource. After I ask Form Wizard to create class for this resource it generates header and cpp file correctly except one thing - my class does not recognize control ID that appears in class code like ID_BLABLABLA. After including resource.h - everything goes fine. But why wizard doesn't do it automatically?
This is dialog header:
#pragma once
// dlg4 dialog
class dlg4 : public CDialogEx
{
DECLARE_DYNAMIC(dlg4)
public:
dlg4(CWnd* pParent = NULL); // standard constructor
virtual ~dlg4();
// Dialog Data
enum { IDD = IDD_DIALOG2 };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
DECLARE_MESSAGE_MAP()
};
dialog cpp:
// dlg4.cpp : implementation file
//
#include "stdafx.h"
#include "dlg4.h"
#include "afxdialogex.h"
// dlg4 dialog
IMPLEMENT_DYNAMIC(dlg4, CDialogEx)
dlg4::dlg4(CWnd* pParent /*=NULL*/)
: CDialogEx(dlg4::IDD, pParent)
{
}
dlg4::~dlg4()
{
}
void dlg4::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(dlg4, CDialogEx)
END_MESSAGE_MAP()
// dlg4 message handlers
The wizard includes the app class h file. The app class h file includes resource.h
It is quite reasonable for you to remove the include of app.h and replace it with resource.h

zoom the Image Element in QML. without using QImage::scaled(), QPixmap::scaled().

I am trying to implement zoom in / out of a image using Image Element in QML.
I want the Pixel scale to be modified if i double click / pinch zoom.
How can i implement this without using QImage::scaled(), QPixmap::scaled().
Basically i dont want to involve Qt logic into my application.
I want Similar effect to hat is happening in the following tutorial
http://harmattan-dev.nokia.com/docs/library/html/qt4/widgets-imageviewer.html
But without Qt Logic in the app.
i know it's not the best answer but i cannot write a comment (i got less then 50 reps...) but zooming in/out qml is easy using PinchArea if you add a MouseArea you can also use onClicked or onDoubleClicked.... there is a useful example for pinch to zoom here(qt.git).
The ImageViewer example you posted got features like print save and so on, and you don't want to use "qt Logic", so i think you will need to use "qt Logic". I would wirte one class for each feature and implement it where i need it.
first of all i think this could help you(Extending QML Functionalities using C++).
Here a (not tested) example for saveing and reading a file:
fileio.h
#ifndef FILEIO_H
#define FILEIO_H
#include <QObject>
#include <QVariant>
class FileIO : public QObject
{
Q_OBJECT
public:
Q_PROPERTY(QString source
READ source
WRITE setSource
NOTIFY sourceChanged)
explicit FileIO(QObject *parent = 0);
Q_INVOKABLE QString source();
Q_INVOKABLE QVariant read();
Q_INVOKABLE bool write(const QVariant& data);
public slots:
void setSource(const QString& source) ;
signals:
void sourceChanged(const QString& source);
void error(const QString& msg);
private:
QString mSource;
};
#endif // FILEIO_H
and fileio.cpp
#include "fileio.h"
#include <QFile>
#include <QDataStream>
#include <QString>
#include <QDebug>
FileIO::FileIO(QObject *parent) :
QObject(parent){
}
QString FileIO::source(){
return mSource;
}
QVariant FileIO::read()
{
if (mSource.isEmpty()){
emit error("source is empty");
return QVariant();
}
QFile file(mSource);
QVariant fileContent; // i dont know if you can use QImage but i think you cann't
if ( file.open(QIODevice::ReadOnly) ) {
QDataStream t( &file );
fileContent << t //you may have to reimplement "<<" operator
file.close();
} else {
emit error("Unable to open the file");
return QVariant();
}
return fileContent;
}.....
and register that in main.cpp like
qmlRegisterType<FileIO, 1>("FileIO", 1, 0, "FileIO");
so you can import it in your qml like
import FileIO 1.0
Rectangle{
id: someId
...
FileIO{
id: yourAccessToYourFileIOclass
}
}
i've not tested that code yet, i hope it helps.
for better answers post what you want to do exacly save, print , any filters....
p.s. I also would create a model in qt and bring it to qml...
greez Matthias

QWidget pos() not updated during resizes involving origin

I am desperately failing at the supposedly simple problem to obtain the position and geometry of a Qt window on the screen. I originally stumbled upon this problem in a Python/PyQt context, but have since tracked it to Qt itself, where the QWidget::pos() property is not updated when the user resizes the window using any of the top or left edges or corners, i.e., resizes that involve the origin at the top left corner, hence the position of the window.
The following Qt/C++ program is the minimum to reproduce the problem (name as Qt_test.cc and build with qmake -project Qt_test.cc; qmake; make):
#include <QApplication>
#include <QWidget>
#include <QPushButton>
#include <QDebug>
class PrintingQWidget : public QWidget {
Q_OBJECT
public slots:
void print() {
qDebug() << pos() << width() << height();
}
};
#include "Qt_test.moc"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
PrintingQWidget window;
QPushButton btn("Print position", &window);
window.connect(&btn, SIGNAL(clicked()), SLOT(print()));
window.show();
return app.exec();
}
Click on "Print position" to obtain the coordinates of the window, then resize the window using the top or left edges, and click again. On my system (MacOSX), the window position in the QWidget::pos() property was not updated. I clearly understand from the documentation that QWidget::pos() should always yield the coordinates of the top-left corner of the widget, which is not the case.
Anyone able to reproduce this problem? Any workarounds?
OK, it appears that this is actually a bug in Qt 4.8. My example program, as well as Merlin069's version, behave perfectly fine with Qt 5. Both Qt 4.8.2 and Qt 4.8.4 are affected by the bug. (For Qt 4.8.4, I tested both the homebrew and dmg installations, which both behave incorrectly). My test system was MacOSX 10.7.5.
Maybe some of you with different systems/Qt versions can still run the test program and report back, so that I can file a better bug report?
Looking closer at your code, you should not be including the moc file. Anyhow, I decided to code this myself and I get the correct, expected coordinates in screen space. Here's the code: -
Header (widget.h)
#include <QWidget>
#include <QDebug>
class MyWidget : public QWidget
{
Q_OBJECT
public:
MyWidget(QWidget* parent = NULL)
: QWidget(parent)
{
}
virtual ~MyWidget()
{
}
public slots:
void PrintPos() const
{
qDebug() << pos() << width() << height();
}
};
Main.cpp
#include "widget.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
MyWidget debugWidget(NULL);
QPushButton btn("print position", &debugWidget);
QObject::connect(&btn, &QPushButton::released, &debugWidget, &MyWidget::PrintPos);
debugWidget.show();
return app.exec();
}

Resources