I've recently set up qt creator to work with SFML, and I tried running a piece of code as a test to see if it works. I must note the code bellow works perfectly in Codeblocks IDE but in qt creator it simply displays a console with the text "Press RETURN to close this window..."
#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <iostream>
using namespace std;
using namespace sf;
Window w(VideoMode(350,350,32), "Tic Tac Toe"); Event e1; const Input&
in1 = w.GetInput();
int main() {
while(w.IsOpened())
{
w.Display();
}
return EXIT_SUCCESS;
}
Here is my .pro file:
INCLUDEPATH += C:\SFML-1.6\include
LIBS += C:\SFML-1.6\lib\sfml-system.lib \
C:\SFML-1.6\lib\sfml-window.lib \
C:\SFML-1.6\lib\sfml-graphics.lib \
C:\SFML-1.6\lib\sfml-audio.lib \
C:\SFML-1.6\lib\sfml-network.lib
Never in a million years did I imagine working with SFML on my favorite IDE is so difficult, what is the problem?
Related
I have installed the last QT Creator, running a gived example code, but i get
error: 'QGLFormat' file not found and
error: 'QGLWidget' file not found
My pro file looks like
GLEW_PATH = ../ext/glew-1.9.0
GLM_PATH = ../ext/glm-0.9.4.1
TEMPLATE = app
TARGET = myfilename
LIBS += -Wl,-rpath $${GLEW_PATH}/lib -L$${GLEW_PATH}/lib
LIBS += -lGLEW -lGL -lGLU -lm
INCLUDEPATH += $${GLEW_PATH}/include $${GLM_PATH}
SOURCES = main.cpp viewer.cpp
HEADERS = viewer.h
CONFIG += qt opengl warn_on thread uic4 release
QT += core gui opengl xml widgets
The errors happen here in my only header viewer.h, but others includes look fine
// GLEW lib: needs to be included first!!
#include <GL/glew.h>
// OpenGL library
#include <GL/gl.h>
// OpenGL Utility library
#include <GL/glu.h>
// OpenGL Mathematics
#include <glm/glm.hpp>
#include <QGLFormat> //Error here
#include <QGLWidget> //and here
#include <QMouseEvent>
#include <QKeyEvent>
...
with a main quite simple
#include <qapplication.h>
#include <QString>
#include "viewer.h"
int main(int argc,char** argv) {
QApplication application(argc,argv);
Viewer viewer;
viewer.show();
return application.exec();
}
Recently build OPENCV 3.4.3 with CMAKE 3.12.4 and MINGW64(32bit) 8.1.0 in Windows 7. Have QT 5.6 and i trying to test this build as QT Console App, but when i compiling with QT only get the message "Press "RETURN" to close this window...".
.PRO file:
CONFIG += c++11
TARGET = test
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
OTHER_FILES += test.png
INCLUDEPATH += C:\Users\Test\Desktop\opencv\build\include
LIBS += C:\Users\Test\Desktop\mingw\bin\libopencv_*.dll
main.cpp:
#include <QCoreApplication>
#include <iostream>
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv/cv.h"
using namespace std;
int main(int argc, char *argv[]) {
QCoreApplication a(argc, argv);
cout << "Hello World!" << endl;
cv::Mat mat;
mat = cv::imread("test.png");
cvNamedWindow("hello");
cv::imshow("hello",mat);
return a.exec();
}
What im doing wrong?
Imo the problem is not in your code, I just run it (using Qt5.5, Win10, openCV 4 and mingw64), even if I had to change cvNamedWindow to cv::namedWindow.
I have two hints:
did you build openCV with mingw64? If not, do so.
are the openCV dlls in the path when you run the application? You can also copy all opencv dlls in the program folder to check that quickly...
I am trying to embed the gnuplot window into my application using the socket/plug concept in gtkmm 3 library. I have followed the example in the official page here and everything works as expected.
Then I moved to embedding gnuplot window. I modified the socket.cpp as follows:
#include <iostream>
#include <fstream>
#include <gtkmm.h>
#include <gtkmm/socket.h>
using namespace std;
class MySocketWindow : public Gtk::Window
{
public:
MySocketWindow()
{
auto socket = Gtk::manage(new Gtk::Socket());
add(*socket);
cout << "Socket id is: " << hex << socket->get_id() << endl;
show_all();
}
};
int main(int argc, char** argv)
{
auto app = Gtk::Application::create(argc, argv, "org.gtkmm.example.socket");
MySocketWindow win;
app->run(win);
return 0;
}
I compile/build the code with:
g++ --std=c++11 socket.cpp -o socket `pkg-config gtkmm-3.0 --cflags --libs`
And run it. A black socket window appears with Socket id is 3e0000b message printed on the terminal.
.\socket
Then I run gnuplot in x11 terminal with the corresponding window id above:
Now when I plot sin(x) in gnuplot, I am expecting the socket window to show the plot, but nothing happens. What I am doing wrong here?
I am running Ubuntu 16.04, 64-bit.
I found the cause of the problem on gnuplot's site - see my original question. Now it's left to find how to fix it on the socket's site.
My goal is to run a simple OpenCV contribute (extra) module in Qt 5.5.1.
Steps:
1) created a Qt Application app;
2) changed the main.cpp file to :
#include <QApplication>
#include <opencv2/core/utility.hpp>
#include <opencv2/tracking.hpp>
#include <opencv2/videoio.hpp>
#include <opencv2/highgui.hpp>
#include <iostream>
#include <cstring>
#include <QDebug>
using namespace std;
using namespace cv;
int main(int argc, char*argv[])
{
qDebug() <<"start!" << endl;
QApplication a(argc, argv);
string trackingAlg = "KCF";
MultiTracker trackers(trackingAlg);
qDebug() <<"success!" << endl;
return a.exec();
}
and here is my .pro file:
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = tracker4
CONFIG += c++11
TEMPLATE = app
SOURCES += main.cpp
INCLUDEPATH += /usr/local/include/opencv
LIBS += `pkg-config opencv --libs`
LIBS += -L/usr/local/lib -lopencv_core -lopencv_imgcodecs -lopencv_highgui -lopencv_videoio -lopencv_tracking
The program compiles successfully, but in the runtime, it crashes without even running the main() function. I don't get such an error when I run this in Code::Blocks but in Qt I still have this issue.
I am using Qt 5.5.1 and Ubuntu 14.04.
Can anyone generate this "seg fault" error in his/her machine?
For QT 5, build the OpenCV with QT=OFF.
For QT 4, build the OpenCV with QT=ON.
I saw this question already on this forum but I do not know why the proposed answer does not work in my case. So I try to ask for other slution.
I just got my Qt creator running under Linux.
I do not understand why my:
cout << "This does not appear";
Does not print in console while qdebug does
qDebug() << "This appears";
This is what is contained in my .pro file:
QT += core gui
TARGET = aaa
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp \
IeplcModule.cpp
HEADERS += mainwindow.h \
IeplcModule.h
FORMS += mainwindow.ui
#enable console
CONFIG += console
Any idea?
Try with:
cout << "asdf" << endl;
Possibly Qt sets up iostream in order to flush only at new line.
When debugging with CDB (Windows debugger) and running application not in the dedicated terminal window, but within QtCreator output panel, there is an issue with std::cout/std::cerr.
qDebug works because it has a trick for this case.
So, the only solution in this case is enable the "run in terminal" option.
For more infor please follow the link above to the Qt bug tracker.
Is it possible that STDOUT is redirecting? qDebug prints to STDERR by default.
Did you #include <iostream>? I did not see any includes in the code.
I assume that qdebug and cout are very similar.
Make sure you have console config enabled in your .pro file. I.e. :
CONFIG += console
You can run this program from CMD and it will print some messages to the console:
/* Create a .pro file with this content:
QT += core gui widgets
SOURCES += main.cpp
TARGET = app
-------------------------------
Build and run commands for CMD:
> qmake -makefile
> mingw32-make
> "release/app"
*/
#ifdef _WIN32
#include <windows.h>
#endif
#include <QtCore/QFile>
#include <QtCore/QString>
#include <QtCore/QIODevice>
#include <QtWidgets/QApplication>
#include <QtWidgets/QWidget>
#include <iostream>
class Widget : public QWidget
{
public:
Widget()
{
setWindowTitle("My Title");
QString path("assets/text.txt");
std::cout << std::endl;
std::cout << "hello1" << std::endl;
std::cout << path.toStdString() << std::endl;
std::cout << "hello2" << std::endl;
}
};
int main(int argc, char *argv[])
{
#ifdef _WIN32
if (AttachConsole(ATTACH_PARENT_PROCESS))
{
freopen("CONOUT$", "w", stdout);
freopen("CONOUT$", "w", stderr);
}
#endif
QApplication app(argc, argv);
Widget w;
w.show();
return app.exec();
}