Qt creator cannot find, QTcpServer and QTcpSocket - c++

Eventhough, I put 'network' in .pro file,
My Qt creator cannot find QTcpSocket and QTcpServer.
What should I do?
I remove the Qtcreator and redownloaded already but it also did not work.
My Linux version is Ubuntu 14.04 LTS
and I downloaded QT Creator by linux commands.
sudo apt-get install qtcreator
I even do the linus updates because I worried that I missed something.
sudo get-apt update
sudo get-apt upgrade
Why Qtcreator cannot perceive QTcpServer and QTcpSocket headers?
--------------*.pro -----------------------------------
QT += core gui network
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = server11
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
-------------------mainwindow.h--------------------------------------
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QTcpSocket>
#include <QTcpServer>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H

Did you install the complete framework? Or just the IDE?
Try downloading the Qt offline installer and downloading the framework through it. Download and install it from here.
Qt Open Source
Instructions for Ubuntu

Related

The program has unexpectedly finished in QT opencv

I know that this has been posted many times,but I could not find the solution from previous posts. I followed tutorial on How to setup Qt and openCV on Windows from wiki Qt.
My .pro file and mainwindows.cpp are shown below. I wanted to open image following the example. What is wrong here? Checked the opencv version and it is the same as libs included. The PATH is also correct.
The cpp file
#include "ui_mainwindow.h"
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
cv::Mat image = cv::imread("C://1.jpg", 1);
cv::namedWindow("My Image");
cv::imshow("My Image", image);
}
MainWindow::~MainWindow()
{
delete ui;
}
and
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = opencvtest
TEMPLATE = app
DEFINES += QT_DEPRECATED_WARNINGS
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
INCLUDEPATH += C:\opencv\build\include
LIBS += C:\opencv-build\bin\libopencv_core451.dll
LIBS += C:\opencv-build\bin\libopencv_highgui451.dll
LIBS += C:\opencv-build\bin\libopencv_imgcodecs451.dll
LIBS += C:\opencv-build\bin\libopencv_imgproc451.dll
LIBS += C:\opencv-build\bin\libopencv_features2d451.dll
LIBS += C:\opencv-build\bin\libopencv_calib3d451.dll
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = nullptr);
~MainWindow();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
When program crashes like that under Qt Creator, and you have extra libraries, the very likely reason is that the extra libraries are missing from the runtime PATH.
In this case, you need to add C:\opencv-build\bin to the PATH. There are at least 3 ways to go about it.
Edit the system environment, so that the relevant directory is always in the system PATH. You need to restart Qt Creator for this change to take effect. This is not the recommended way, unless you actually want these things in there also for other purposes.
You can edit the Build environment of the project under Qt Creator Project view. There's separate configuration for each build type, so you may need to do this to them all separately, which both good and bad. It is good, because then you can have different directory for different builds (for example debug vs relase, MSVC vs MinGW builds). It's bad because it's extra hassle and makes it easier to have something wrong.
You can add it to the run environment in the Qt Creator Project view. Then it will be the same for all build types.
In this case, 3 is probably the way to go.
Qt Creator annoyingly does not display any information about which DLL is missing, it just says the program crashed. This can be solved by instead string the "Qt command prompt" for the correct toolchain from Windows Start menu (search Qt and you should find it). Then go to the built .exe directory and run the .exe. You should now get an error dialog where Windows tells you which DLL it failed to find. Then you can look where that DLL is and add it to the path and try again, until the program starts. After you know the directories using this method, you can then add them to Qt Creator as explained above.

QTCreator g++.exe: fatal error: no input files (Windows)

An error occurs during the build:
code *.pro:
QT += core gui
QT = widgets
TARGET = MYPROJECT
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
code mainwindow.h:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
As a compliant is installed: C:\Strawberry\c\bin\g++.exe
The assembly is made in Windows 10 64 bit.
In time the assembly i get so error:
g++.exe: fatal error: no input files
compilation terminated.
09:38:38: The process "C:\Strawberry\c\bin\g++.exe" ended with code 1.
Error in assembling / installing the MYPROJECT project (set: MYPROJECT_DESCTOP)
During the "Build" stage
I tried include full path to files in .pro file, but it isn't helped.
Make sure you have all your code files in the current working directory, otherwise you'll have to include their path in the compile command.

Simple Qt project with openCV instantly crash

I try to use openCV in a Qt project. But my release build instantly crash on launch if I link the release libs of openCV. Debug libs allow the programm to start but the application crashes when I try to use openCV functions (it is known that mixing release/debug in openCV causes some crash).
So I made a simple project and it won't even launch. Both release and debug build crashes and using debugger causes a small window saying 'unexpected CDB exit'.
Here are the source.
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = test_openCV
TEMPLATE = app
#flags to generate a .map file
QMAKE_LFLAGS_RELEASE +=/MAP
QMAKE_LFLAGS_RELEASE += /debug
SOURCES += main.cpp\
MainWindow.cpp
HEADERS += MainWindow.h
FORMS += MainWindow.ui
INCLUDEPATH += $$PWD
INCLUDEPATH += "D:/openCV/build/include"
#Switching between handbuild and the build I downloaded have no effect.
#I am sure the path are good. Quadra checked.
#LIBS += -L"D:/openCV/build/x64/vc11/lib"
LIBS += -L"D:/openCV/hand_build/lib/Release"
LIBS += -L"D:/openCV/hand_build/lib/Debug"
#disables the "fopen not secure" warning in openCV.
DEFINES += _CRT_SECURE_NO_WARNINGS
win32:CONFIG(release, debug|release): LIBS += -lopencv_core2413 -lopencv_highgui2413 -lopencv_imgproc2413
else:win32:CONFIG(debug, debug|release): LIBS += -lopencv_core2413d -lopencv_highgui2413d -lopencv_imgproc2413d
main.cpp:
#include "MainWindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
MainWindow.h:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <opencv/cv.h>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
and MainWindow.cpp:
#include "MainWindow.h"
#include "ui_MainWindow.h"
#include "opencv2/core.hpp"
#include "opencv2/highgui.hpp"
#include <QDebug>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
//Removing this line will causes the program to start normally (guess it won't link the libs if nothing from openCV is used).
cv::Mat image;
}
MainWindow::~MainWindow()
{
delete ui;
}
What I get when launching app:
Starting D:\Colin\build_test_openCV\release\test_openCV.exe...
program suddenly ended
D:\Colin\build_test_openCV\release\test_openCV.exe crashed
I work on Windows 7 / MSCV2012 openGL 64bits / Qt 5.2.1 openGL.
Does anyone see a mistakes I could have made?
I have a similar setup as yours and was getting the exact same problem. The issue was that the path to the corresponding dlls was not defined. These dlls:
opencv_core2411.dll
opencv_highgui2411.dll
opencv_imgproc2411.dll
should be in D:/openCV/hand_build/bin/ (or maybe D:/openCV/hand_build/bin/Release/). Adding another line:
LIBS += -L"D:/openCV/hand_build/bin/Release/"
should work.
I just had a similar issue. The program was crashing because it could not find the appropriate DLL at runtime. Adding the OpenCV directories to my Windows PATH fixed the problem for me.
All items in your build must have been built using the same Visual Studio version, that means:
The Qt install you're using.
OpenCV.
Your code.
Most likely at least one of the above was not built using the same compiler. If OpenCV is linked against Qt, it must have been built against a binary-compatible version of Qt, too.

Qt 5.5 QOpenGLWidget link error not linking any openGL calls

I tried to build a simple OpenGL App with Qt 5.5.1, and everything is fine up until I try to use openGL native function calls like glClearColor.
The Widget actually compiles and produces a black screen, but after I try to use any openGL native function it doesn't even link, but produces the error:
glwidget.cpp:10: error: undefined reference to '_imp__glClearColor#16'
Here is the .pro file:
QT += core gui opengl
CONFIG += windows
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = Vehicle_simulation
TEMPLATE = app
SOURCES += main.cpp\
simulation.cpp \
glwidget.cpp
HEADERS += simulation.h \
glwidget.h
FORMS += simulation.ui
I'm using Desktop Qt mingw492_32 kit.
The strange thing though is that I did not find libQtOpenGL.so in the lib folder. Is my QT installation faulty? I tried to reinstall it multiple times, but it didn't help. Where can I download that specific library?
linking it to the project would solve the problem, but I can't seem to find it anywhere.
The problem is the openGL module is missing from the QT installation, it's not that I am unable to link to it.
After I opened up an example program by chance, just to take a look at the implementation; I found that the same QOpenGLWidget has been implemented in a new example program.
After a bit of analysis I managed to figure out the problem.
QT has an internal openGL implementation and native openGL support as well. The widget I used inherited from QOpenGLWidget, but the openGL function calls (like glClearColor) tried to access native openGL implementation in Qt. which Since those were not included in my Qt build, the project would not build.
To fix this one has to either run a custom Qt core build, or use the openGL wrapper provided by Qt.
I used the Qt wrapper in the end, which was also used by the example program Cube. the class used to implement the widget (called GLWidget in my implementation) has to inherit not only from QOpenGLWidget, but also from QOpenGLFunctions. The latter part was missing from my implementation. The source code for it is the following:
glwidget.h (initial):
#ifndef GLWIDGET_H
#define GLWIDGET_H
#include <QOpenGLFunctions>
#include <QOpenGLWidget>
class GLWidget : public QOpenGLWidget
{
Q_OBJECT
public:
explicit GLWidget(QWidget *parent);
protected:
void initializeGL();
void paintGL();
void resizeGL(int w, int h);
};
#endif // GLWIDGET_H
glwidget.h (fixed):
#ifndef GLWIDGET_H
#define GLWIDGET_H
#include <QOpenGLFunctions>
#include <QOpenGLWidget>
class GLWidget : public QOpenGLWidget, protected QOpenGLFunctions
{
Q_OBJECT
public:
explicit GLWidget(QWidget *parent);
protected:
void initializeGL() Q_DECL_OVERRIDE;
void paintGL() Q_DECL_OVERRIDE;
void resizeGL(int w, int h) Q_DECL_OVERRIDE;
};
#endif // GLWIDGET_H
Be careful!
Before any gl* functions are used the function initializeOpenGLFunctions(); has to be called, otherwise a very cryptic run-time error will pop up.
i.e.:
void GLWidget::initializeGL(){
initializeOpenGLFunctions();
glClearColor(1,0,0,1);
}
Hope this will help someone else as well.

Debug Assertion Failed (unsigned)(c+1) <= 256 (in VideoCapture::open [Qt Creator])

I've been trying to use cv::VideoCapture::open("< path to video file >") in QtCreator (opencv added). Even though the program runs without errors in "bebug mode" (debug build), it gives below runtime error in "release mode" (release build).
Debug Assertion Failed File:
f:/dd/vctools/crt_bld/self_x86/src/isctype.c Line: 56 Expression:
(unsigned)(c+1) <= 256
It is a simple program which uses only cv::VideoCapture::open() [for testing purposes]
Below is the .pro file
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = untitled
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
INCLUDEPATH += C:/C/opencv/build/include
INCLUDEPATH += C:/C/opencv/build/include/opencv
LIBS += C:/C/opencv/build/x86/vc10/lib/opencv_highgui240d.lib
LIBS += C:/C/opencv/build/x86/vc10/lib/opencv_highgui240.lib
LIBS += C:/C/opencv/build/x86/vc10/bin/opencv_highgui240d.dll
LIBS += C:/C/opencv/build/x86/vc10/bin/opencv_highgui240.dll
Below is the Header file
#include <QMainWindow>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/core/core.hpp>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
cv::VideoCapture vcap;
};
Below is the .cpp file
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
vcap.open("C:/Users/ANURUDDHA/pedestrians/ThreePastShop2cor.mpg");
}
MainWindow::~MainWindow()
{
delete ui;
}
When I pass an int as the argument to cv::VideoCapture::open() [eg: vcap.open(0)] it runs without errors in both debug and release build and opens webcam successfully. Problem comes only when I pass a String to arguments.
Someone please shed some light on this. Really appreciated.
It looks like you're linking in both debug and release versions of the libs (twice?). That's caused me problems in the past before. Try using only LIBS += C:/C/opencv/build/x86/vc10/bin/opencv_highgui240.dll for release builds and LIBS += C:/C/opencv/build/x86/vc10/bin/opencv_highgui240d.dll for debug builds.
Also, 0 is the same as NULL. Probably the library aborts doing whatever it was doing (whether in debug or release) prior to the assert fail. You shouldn't be getting assert fails in release mode, but the fact that you are tells me that the debug library was loaded in your program that you compiled for release mode.
Edit:
Looks like somebody already answered you here:
http://answers.opencv.org/question/15838/videocaptureopenqt-creatordebug-assertion-failed/
I guess I found the answer though it seems kinda ambiguous to me. Anyway, now the program works in release mode.
Hope this might help someone in someway.
I copied dll files inside C:/C/opencv/build/x86/vc10/bin/ to Windows system folder. That is C:\Windows\SysWOW64. In case if someone is using a 32 bit version of Windows it should be System32.