1

I'm a beginner "programmer", and I'm using quotation marks because I'm THAT green.

Windows 7 64-bit
Code::Blocks 13.12
OpenCV 2.4.10
Qt 4.8.5

I've been thrown into single-handedly creating a pretty big (for me) piece of software that uses OpenCV and mingw to track movement of a few different markers and calculate (and accurately guess...) a lot of things. I'm almost done, but and I have to incorporate some GUI elements into it, most importantly a dialog window with which you can look for files (came up yesterday). So I've tried setting up Qt with Code::Blocks and creating a basic Hello World app. I've set up the env Path variable, I've pointed the linker and compiler search directories where they should be. It still doesn't work.

#include <QApplication>
#include <QFont>
#include <QPushButton>

int main(int argc, char* argv[])
{
QApplication app(argc, argv);

QPushButton quit("Quit");

quit.resize(75, 30);
quit.setFont(QFont("Times", 18, QFont::Bold));

QObject::connect(&quit, SIGNAL(clicked()), &app, SLOT(quit()));

quit.show();

return app.exec();
}

This is the thing I am trying to run. Compiles fine, no errors or warnings. But when I run it, it immediatly stops working, as in "Qt.exe has stopped working" and process returns -1073741819... it crashes the moment it tries to do something Qt-specific (QApplication...)

I added a simple cout << "Hello world"; before QApplication app(argc, argv);, and it displayed in the console, and then stopped working.

Even when I bare the code down to
QApplication app(argc, argv); return app.exec();
it still crashes the same way.

My first question... what could possibly be the problem? I ran out of ideas and Google doesn't want to help me either. I've tried using the Qt Creator, and it worked fine, but I couldn't get it to work... it'd just print "Naci" into the console, regardless of what project I tried to run, and I have no idea what "Naci" is and where it came from.
PS: And another question. Is it possible to create a console app that at one point calls a function that has the QDialog window and gets filename from it?

edit: I'm trying to run examples attached to Qt release. They all give me undefined reference to vtable errors and none of the solutions I've found around work. Jesus... this is not friendly towards new people edit2: I'm going to rebuild and reconfigure Qt... on my 1ghz netbook it's probably going to take a while...

Petersaber
  • 851
  • 1
  • 12
  • 29
  • I've never seen any `QWidgets` being used (in your case, the push button) without having them inside a `QMainWindow`. I am not sure if this could work but I'd suggest creating a `QMainWindow` with the button as a child. It should be like that in the examples as well. – Bowdzone Apr 15 '15 at 09:58
  • concerning creating a QDialog window I think it is possible. For Linux I can `fork()` console app to give QDialog as child process. then send back filename to Parent process "console app" through `pipe()`, but for windows may be it is possible through `CreatProcess()`. – youssef Apr 15 '15 at 10:09
  • Did you copy Qt dll libs to the build folder? They are needed to run any Qt app. You have QtCreator in polish language. In console, it prints that app has ended and you need to press Return to close console. Because of polish letter "ś" console drops rest of the text "Naciśnij Return aby zamknąć" – firescreamer Apr 15 '15 at 10:16
  • Your code works for me, but I'm using Qt5 and QtCreator. – firescreamer Apr 15 '15 at 10:17
  • @firescreamer - that's interesting. But still, that means the whole code was ignored, doesn't it? Copying dll libs didn't help. Wouldn't the error be different if they were missing? – Petersaber Apr 15 '15 at 10:21
  • @Youssef - thanks, I'll try that if I solve my Qt problems – Petersaber Apr 15 '15 at 10:23
  • Try running app from windows. What error message says? On your PS question see: http://stackoverflow.com/questions/12866490/qfiledialoggetopenfilename-in-console-application – firescreamer Apr 15 '15 at 10:28
  • @firescreamer Same story. "Stopped working". – Petersaber Apr 15 '15 at 10:32
  • @Bowdzone - it still happens. Even if I bare the code down to nothing but "QApplication app(argc, argv); return app.exec();" it still crashes the same way – Petersaber Apr 15 '15 at 11:11
  • I would try to reinstall Qt, because your code should compile and work out of box in Qt Creator. Can you show pro file? And why are you using Qt 4.8 when Qt 5.4 is already out? – firescreamer Apr 15 '15 at 11:28
  • Make sure your compiler matches with the one Qt was compiled with. See [this](http://stackoverflow.com/a/13978119/2257050) answer. – thuga Apr 15 '15 at 11:28
  • @firescreamer I'm using Code:Blocks, not Qt Creator. For various reasons. One of them being the absolute refusal of QtC to work with existing OpenCV projects. That code which doesn't want to work is the default Hello World code. Why 4.8.5? To be honest, I've had so many problems with the mess my predecesor left that when I saw a project working with OpenCV 2.4.10 and a Qt, I grabbed exactly that Qt. I've tried 5.4 with Creator, but it refused to work with OpenCV 2.4.10 and that project. – Petersaber Apr 15 '15 at 11:40

1 Answers1

0

I reconfigured Qt and then rebuilt it via MingW again. Even though after 6 hours compilation failed, it did enough... and now Qt works with Code::Blocks. Odd. I've done that before, no idea why this time it worked and the last time it didn't.

For those who don't know how to do that, run command line (if on Windows), go to the main folder of Qt (the one with include, bin, lib (etc) folders, in my case C:\Qt\4.8.5), type configure.exe (use configure.exe -help to see available parameters) and after it's done configuring just go mingw32-make and wait for an hour or ten.

Petersaber
  • 851
  • 1
  • 12
  • 29