Compiler can't find ui_xyz.h file - c++

I've install Netbeans 7.2 and Qt 5 on Windows7. Everything compiles fine.
But recently when I create a Qt form and try to use it in this way:
New Project > C/C++ Qt Application > Finish
Right click on new Qt project > New > Qt Form > Finish
After saving ui file in Designer
This error appears:
newForm.h:11:24: fatal error: ui_newForm.h: No such file or directory
The content of main.cpp is :
#include <QGuiApplication>
#include "newForm.h"
int main(int argc, char *argv[])
{
// initialize resources, if needed
// Q_INIT_RESOURCE(resfile);
QGuiApplication app(argc, argv);
// create and show your widgets here
return app.exec();
}
I tried to manually create ui_xwz.h file and add it to my project. But I want it work automatically as same as before. How can I solve it?

I have a ridiculous solution, Maybe we should report it as a bug to Netbeans or Qt.
Go and active QtSVG and QtXml modules of your project and rebuild it. I tested this way and the problem vanished.

Related

QSystemTrayIcon not showing after using windeployqt tool [duplicate]

This question already has answers here:
QSystemTrayIcon and Windows8
(2 answers)
Closed 3 years ago.
Note: Yes, this question has been asked and answered previously, but the duplicate's answer is incomplete. Please see my solution if you are stuck on this.
Using Qt 5.13.0 MSVC2017 64-bit and Windows 10, I'm experiencing some strange behavior from QSystemTrayIcon. When running in Debug or Release from QtCreator on a fresh build, there are no issues and the icon displays exactly how I would expect it to. However, after using the windeployqt.exe tool, the icon stops showing up.
This happens both when I run it from QtCreator after windeployqt.exe and from the installation directory via Qt Installer Framework. If I delete the build directory, clean, and rebuild, the problem goes away, but obviously this is an issue for deployment.
Command:
windeployqt.exe <RELEASE_DIR>
(also tried specifying the executable directly)
MainWindow constructor:
AltheaWindow::AltheaWindow(MacroListModel &macroListModel, Config *config, const QString &configPath, QWidget *parent)
: QMainWindow(parent),
ui(new Ui::AltheaWindow),
macros(macroListModel),
config(config),
trayIcon(QIcon(IconPath), this),
shortcutNew(ShortcutPtr(new QShortcut(NewMacro, this))),
shortcutSave(ShortcutPtr(new QShortcut(SaveMacro, this))) {
qDebug() << "AltheaWindow";
ui->setupUi(this);
ui->sidebar->createSettingsDialog(config, configPath);
initConnections();
QFile f(IconPath);
bool exists = f.exists();
qDebug() << "exists = " << exists; // "exists = true"
trayIcon.show();
ui->sidebar->setMacros(&macroListModel);
if ((*(*config)[AltheaConfig::StartMinimized]).toBool()) showMinimized();
}
Regardless of whether the icon is shown or not, exists is always true, so it doesn't seem to be an issue of resolving the resource. All other resources in the application work fine as well.
Found the solution, copy imageformats to the plugins directory.
Solution: https://stackoverflow.com/a/20594583/2472874
Additional note:
For anyone experiencing this issue, I found that I also needed to have the imageformats plugin on the Library Paths before the application object is initialized.
#define PLUGINS "plugins"
void preInit(char *argv[]);
int main(int argc, char *argv[]) {
#ifndef _DEBUG
preInit(argv);
#endif
Althea app(argc, argv);
AltheaWindow w(app.getMacros(), &app.getConfig(), app.getAppData().absoluteFilePath(Althea::ConfigFileName));
w.show();
return app.exec();
}
void preInit(char *argv[]) {
QDir releaseDir(QFileInfo(argv[0]).dir());
QCoreApplication::addLibraryPath(releaseDir.absoluteFilePath(PLUGINS));
}

Invisible text in QTextEdit

I am learning Qt and running examples from Qt SDK 5.9.1. I run the code below and write inside QTextEdit but no text appears. Cursor moves as I write but no text is shown. Window title text is shown. I added addApplicationFont and setFont calls below I found from web to the sample but it didn't help.
#include <QtWidgets>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QFontDatabase::addApplicationFont("://Ubuntu-R.ttf");
app.setFont(QFont("Ubuntu", 11, QFont::Normal, false));
QTextEdit textEdit;
textEdit.show();
return app.exec();
}
I am on Ubuntu 16.04 and run following commands on bash to make executable:
qmake -makefile
make
./part1
I want the app to use the default Ubuntu system font. I learned that Qt uses fontconfig for fonts but I don't know how to trace the issue.
Edit
I thought QFontDatabase::addApplicationFont("://Ubuntu-R.ttf") call referenced system font but instead it is referencing font app resource file. I don't have resource file so obviously it won't work.
.pro file is below(unmodified sample file):
QT += widgets
SOURCES = main.cpp
# install
target.path = $$[QT_INSTALL_EXAMPLES]/widgets/tutorials/gettingStarted/gsQt/part1
INSTALLS += target
I tried to get system font using QFontDatabase but it didn't work:
app.setFont(QFontDatabase::systemFont(QFontDatabase::GeneralFont));
This doesn't do anything with any of enum values including QFontDatabase::GeneralFont
QFontDatabase database;
QStringList fam = database.families();
fam size is zero.
I will try to use embedded font next.
I don't know the exact reason of the problem but the reason was not configuring fontconfig dependency properly before building qt. I solved it by reconfiguring and recompiling qt again. You can find more details at qt forum.

Add Settings entry for iOS app using Qt 5.4

I have built an iOS 8.2 app using Qt 5.4. I want to add a user-entry field in the Settings app like a lot of other apps do, but I can't figure out how to do it. I tried the following (which doesn't work):
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
TDA::TapDisplaySingleton* mainClass =
new TDA::TapDisplaySingleton(&app);
QObject::connect(&app, SIGNAL(aboutToQuit()),
mainClass, SLOT(aboutToQuitApp()));
QGuiApplication::setOrganizationName("NASA Langley");
QGuiApplication::setOrganizationDomain("larc.nasa.gov");
QGuiApplication::setApplicationName("TAP Display");
QSettings settings;
settings.setValue("HOSTNAME", "localhost");
QTimer::singleShot(10, mainClass, SLOT(run()));
return app.exec();
}
When I fire the app up in the Simulator and open the Settings app, my entry does not appear. Does anyone know how to do this effectively in iOS using Qt?
As it turns out, Qt does provide a way to generate a Settings.bundle file for your app. You need to define a Root.plist and Root.strings file in advance and then add the following to your .PRO file:
SETTINGS_BUNDLE_DATA_ROOT.files += Root.plist
SETTINGS_BUNDLE_DATA_ROOT.path = Settings.bundle
SETTINGS_BUNDLE_DATA_LANG.files += Root.strings
SETTINGS_BUNDLE_DATA_LANG.path = Settings.bundle/en.lproj
QMAKE_BUNDLE_DATA += SETTINGS_BUNDLE_DATA_ROOT SETTINGS_BUNDLE_DATA_LANG
When your project is linked, the bundle will be created.
QSettings is only for storing settings in a persistent fashion. Adding settings to the iOS Settings application is outside of the scope of Qt. Look up "iOS Settings Bundle" for information on how to create those - eg https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/UserDefaults/Preferences/Preferences.html .

CodeBlocks Qt HelloWorld.exe has stopped working (C++)

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...
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.

Qt Creator + OpenCV: Program runs from .exe but not from editor

Well, I need to start working with OpenCV and as I'm used to working with QtCreator, I'm trying to make it all work together. I downloaded the latest OpenCV version, and compiled it with MinGW. Then, I created this little console project to try it out. Below is the .pro file:
QT += core
QT -= gui
TARGET = OpenCV_test4
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
INCLUDEPATH += C:\\Librerias\\opencv2.3.1\\release\\include
LIBS += -LC:\\Librerias\\opencv2.3.1\\release\\lib \
-lopencv_core231.dll \
-lopencv_highgui231.dll \
-lopencv_imgproc231.dll \
-lopencv_features2d231.dll \
-lopencv_calib3d231.dll
Here is the main.cpp file:
#include <QtCore/QCoreApplication>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
// read an image
cv::Mat image= cv::imread("img.jpg");
// create image window named "My Image"
cv::namedWindow("OpenCV Window");
// show the image on window
cv::imshow("OpenCV Window", image);
// wait key for 5000 ms
cv::waitKey(5000);
return a.exec();
}
(I have tried this code with and without the QCoreApplication lines)
The deal is: It links and builds, and when runs from QtCreator only a terminal window called C:\QtSDK\QtCreator\bin\qtcreator_process_stub.exe appears with the line "Press RETURN to close this window..."
But, if I run the .exe from the project folder, it runs perfectly!! Why is QtCreator unable to launch the application? I found this really strange, and I would appreciate any hint about this. It's really not THAT important, but it is kind of a pain to have to run the .exe manually every time I change something to check how it works.
Thanks for your time :)
Additional Info:
I have tried both debug and release versions, the problem is the same in both of them.
Debugging does not work, it never stops at any breakpoint.
I'm running on Windows 7 Proffesional x64
SOLVED, I don't really know what I did, it suddenly worked and keeps working, I wish I could tell you how I fixed it but I have no idea, such a weird thing :(
Check Projects -> Run Settings -> Run in terminal. It have to be enabled, but seems to be disabled.
I have met same problem with QtCreator and OpenCL under Linux. Simple test program works after start from terminal and it does not work after start from the QtCreator.
I found the cause was hardcoded LD_LIBRARY_PATH in the project's run environment settings. I had dropped it to empty string and this had fixed issue.
I had the same issue with the following environment: Raspbian, Qt, openCV and a gui application.
old-ufo recommendation worked for me:
- First, enable "Run in terminal", which failed
- Then, disable "Run in terminal", which allowed me to correctly debug my app.
I understand that this is not scientific.