Questions tagged [qt]
Qt is a cross-platform application development framework widely used for the development of application software that can be run on various software and hardware platforms with little or no change in the underlying codebase, while having the power and speed of native applications. Qt is available with both commercial and open source licenses.
86,067
questions
449
votes
9
answers
684k
views
How to convert int to QString?
Is there a QString function which takes an int and outputs it as a QString?
296
votes
12
answers
401k
views
How to convert QString to std::string?
I am trying to do something like this:
QString string;
// do things...
std::cout << string << std::endl;
but the code doesn't compile.
How to output the content of qstring into the ...
272
votes
5
answers
261k
views
Auto-expanding layout with Qt-Designer
I'm using the Qt Designer.
I want to create a QVBoxLayout which will automatically expand to fill the whole window.
The layout of the QVBoxLayout remains fixed.
How can I cause the QVBoxLayout to ...
227
votes
6
answers
474k
views
QLabel: set color of text and background
How do I set color of text and background of a QLabel ?
204
votes
14
answers
47k
views
STL or Qt containers?
What are the pros and cons of using Qt containers (QMap, QVector, etc.) over their STL equivalent?
I can see one reason to prefer Qt:
Qt containers can be passed along to other parts of Qt. For ...
197
votes
12
answers
376k
views
How to print to console when using Qt
I'm using Qt4 and C++ for making some programs in computer graphics. I need to be able to print some variables in my console at run-time, not debugging, but cout doesn't seem to work even if I add the ...
195
votes
7
answers
305k
views
How to change string into QString?
What is the most basic way to do it?
179
votes
4
answers
169k
views
Checking if a folder exists (and creating folders) in Qt, C++
In Qt, how do I check if a given folder exists in the current directory?
If it doesn't exist, how do I then create an empty folder?
175
votes
6
answers
152k
views
How to enable C++11 in Qt Creator?
The title is pretty self-descriptive. I've downloaded Qt Creator 2.7.0, and I am trying to compile some basic C++11 code:
int my_array[5] = {1, 2, 3, 4, 5};
for(int &x : my_array)
{
x *= 2;
}
...
168
votes
4
answers
80k
views
Connecting overloaded signals and slots in Qt 5
I'm having trouble getting to grips with the new signal/slot syntax (using pointer to member function) in Qt 5, as described in New Signal Slot Syntax. I tried changing this:
QObject::connect(spinBox,...
164
votes
11
answers
282k
views
qmake: could not find a Qt installation of ''
I have a software in ubuntu that requires me to run qmake to generate the Makefile.
However, running qmake gives back this error,
qmake: could not find a Qt installation of ''
I have installed ...
160
votes
6
answers
162k
views
How do I handle the event of the user pressing the 'X' (close) button?
In Qt, what is the slot that corresponds to the event of the user clicking the 'X' (close) button of the window frame, i.e., this button:
If there isn't a slot for this, is there any other way to ...
155
votes
22
answers
341k
views
Qt 5.1.1: Application failed to start because platform plugin "windows" is missing
Edit:
Some people started to mark my question as a duplicate. Do not forget that many similar questions existed when I asked this one (see e.g. the list below). However, none of these answers solved ...
155
votes
6
answers
90k
views
What does the Q_OBJECT macro do? Why do all Qt objects need this macro?
I just started using Qt and noticed that all the example class definitions have the macro Q_OBJECT as the first line. What is the purpose of this preprocessor macro?
155
votes
19
answers
13k
views
Beyond Stack Sampling: C++ Profilers
A Hacker's Tale
The date is 12/02/10. The days before Christmas are dripping away and I've pretty much hit a major road block as a windows programmer. I've been using AQTime, I've tried sleepy, ...
154
votes
33
answers
119k
views
Cannot launch AVD in emulator:QT library not found
I am new to Android Studio and I am having problems while using the emulator. When I try to run it keeps crashing saying:
"Cannot launch AVD in emulator" [6816]:ERROR:./android/qt/qt_setup.cpp:28:...
152
votes
6
answers
196k
views
Correct way to quit a Qt program?
How should I quit a Qt Program, e.g when loading a data file, and discovered file corruption, and user need to quit this app or re-initiate data file?
Should I:
call exit(EXIT_FAILURE)
call ...
146
votes
6
answers
48k
views
Detect if stdin is a terminal or pipe?
When I execute "python" from the terminal with no arguments it brings up the Python interactive shell.
When I execute "cat | python" from the terminal it doesn't launch the interactive mode. Somehow, ...
144
votes
3
answers
78k
views
How to build Qt for Visual Studio 2010
I struggled finding a how-to which provides a stable solution for using Qt with Visual Studio 2010, so after collecting all the bits of information and some trial and error, I would like to write my ...
134
votes
2
answers
112k
views
undefined reference to template function [duplicate]
I have three files . The contents of main.cpp are
#include<iostream>
#include<QString>
#include "util.h"
int main()
{
using Util::convert2QString;
using namespace std;
int ...
133
votes
8
answers
210k
views
Yes/No message box using QMessageBox
How do I show a message box with Yes/No buttons in Qt, and how do I check which of them was pressed?
I.e. a message box that looks like this:
130
votes
21
answers
332k
views
"Failed to load platform plugin "xcb" " while launching qt5 app on linux without qt installed
I wrote application for linux which uses Qt5.
But when I am trying to launch it on the linux without Qt SDK installed, the output in console is:
Failed to load platform plugin "xcb". Available ...
129
votes
10
answers
273k
views
QString to char* conversion
I was trying to convert a QString to char* type by the following methods, but they don't seem to work.
//QLineEdit *line=new QLineEdit();{just to describe what is line here}
QString temp=line->...
128
votes
8
answers
249k
views
Adding external library into Qt Creator project
How can I add external library into a project built by Qt Creator RC1 (version 0.9.2)? For example, the win32 function EnumProcesses() requires Psapi.lib to be added in the project to build.
126
votes
8
answers
112k
views
Qt: can't find -lGL error
I just reinstalled QtCreator, created new project (Qt Application) an got this after compilation:
/usr/bin/ld: **cannot find -lGL**
collect2: error: ld returned 1 exit status
make: *** [untitled1] ...
124
votes
8
answers
62k
views
Qt Creator - Project ERROR: Xcode not set up properly. You may need to confirm the license agreement by running /usr/bin/xcodebuild
I just installed Qt 5.5 and am using Qt Creator for the first time on OS X. When I first installed Qt, it gave me an error message 'Xcode 5 not installed' which I thought was strange, (I have the ...
119
votes
12
answers
44k
views
Hand Coded GUI Versus Qt Designer GUI [closed]
I'm spending these holidays learning to write Qt applications. I was reading about Qt Designer just a few hours ago, which made me wonder : what do people writing real world applications in Qt use to ...
118
votes
2
answers
157k
views
Qt c++ aggregate 'std::stringstream ss' has incomplete type and cannot be defined
I have this function in my program that converts integers to strings:
QString Stats_Manager::convertInt(int num)
{
stringstream ss;
ss << num;
return ss.str();
...
118
votes
3
answers
91k
views
Using emit vs calling a signal as if it's a regular function in Qt
Let's say I have this signal:
signals:
void progressNotification(int progress);
I only recently learned about the emit keyword in Qt. Until now, I used to execute signals by just calling them ...
117
votes
8
answers
122k
views
How to build a full path string (safely) from separate strings?
Does C++ have any equivalent to python's function os.path.join? Basically, I'm looking for something that combines two (or more) parts of a file path so that you don't have to worry about making sure ...
116
votes
11
answers
130k
views
How to specify different Debug/Release output directories in QMake .pro file
I have a Qt project and I would like to output compilation files outside the source tree.
I currently have the following directory structure:
/
|_/build
|_/mylib
|_/include
|_/src
|_/resources
...
115
votes
6
answers
119k
views
Convert an int to a QString with zero padding (leading zeroes)
I want to "stringify" a number and add zero-padding, like how printf("%05d") would add leading zeros if the number is less than 5 digits.
114
votes
11
answers
79k
views
How to create a subdirectory for a project QtCreator?
I would like to divide my Qt project into several directories because it is growing pretty large. However, when I click on browse in QtCreator, there is no 'Add directory' and no such thing in 'Add ...
113
votes
10
answers
66k
views
Qt events and signal/slots
In the Qt world, what is the difference of events and signal/slots?
Does one replace the other? Are events an abstraction of signal/slots?
113
votes
6
answers
40k
views
Why Qt is misusing model/view terminology?
I think that the terminology used in Qt with model/view controls is flawed. On their explanation page they state, that they simplified the MVC to MV by merging View and Controller and they are giving ...
110
votes
5
answers
74k
views
Qt Quick vs. Qt Widget [closed]
I am new to Qt and don't quite understand the difference between a Qt Quick Project and a Qt Widget Project.
I am hoping to create a program that draws a lattice of hexagons that the user can rotate ...
110
votes
3
answers
36k
views
Does Qt support virtual pure slots?
My GUI project in Qt has a lot of "configuration pages" classes which all inherit directly from QWidget.
Recently, I realized that all these classes share 2 commons slots (loadSettings() and ...
108
votes
3
answers
74k
views
what does __declspec(dllimport) really mean?
I saw the Qt source code like this:
class Q_CORE_EXPORT QBasicAtomicInt
{
public:
...
};
Which Q_CORE_EXPORT macro defines like below:
define Q_DECL_IMPORT __declspec(dllimport)
So what does ...
108
votes
9
answers
205k
views
How to set image on QPushButton?
I want to set an image on QPushButton, and the size of QPushButton should depend on the size of the image. I am able to do this when using QLabel, but not with QPushButton.
So, if anyone has a ...
106
votes
7
answers
100k
views
How to redirect qDebug, qWarning, qCritical etc output?
I'm using a lot of qDebug() << statements for debug output. Is there any cross-platform way I can redirect that debug output to a file, without resorting to shell scripts? I'm guessing that open(...
106
votes
3
answers
56k
views
Qt: *.pro vs *.pri
What is the difference between *.pro and *.pri configuration files for qmake?
What should go into a *.pro file and what should go into a *.pri file?
105
votes
9
answers
115k
views
What should I choose: GTK+ or Qt? [closed]
Can someone suggest what's the best uses for those libraries today? Is it just GUI, or do they have database, XML, networking, threading, etc support too?
I was reading about them, and considered ...
104
votes
4
answers
131k
views
Convert std::string to QString
I've got an std::string content that I know contains UTF-8 data. I want to convert it to a QString. How do I do that, avoiding the from-ASCII conversion in Qt?
104
votes
6
answers
153k
views
Set QLineEdit to accept only numbers
I have a QLineEdit where the user should input only numbers.
So is there a numbers-only setting for QLineEdit?
103
votes
9
answers
71k
views
How can I hide/delete the "?" help button on the "title bar" of a Qt Dialog?
I am using Qt Dialogs in one of my application.
I need to hide/delete the help button. But i am not able to locate where exactly I get the handle to his help button. Not sure if its a particular flag ...
103
votes
4
answers
66k
views
Memory management in Qt?
I'm quite new to Qt and am wondering on some basic stuff with memory management and the life of objects. When do I need to delete and/or destroy my objects? Is any of this handled automatically?
In ...
102
votes
10
answers
146k
views
Qt: resizing a QLabel containing a QPixmap while keeping its aspect ratio
I use a QLabel to display the content of a bigger, dynamically changing QPixmap to the user. It would be nice to make this label smaller/larger depending on the space available. The screen size is not ...
102
votes
5
answers
45k
views
What is the difference between QImage and QPixmap?
I do not understand what is the difference between QImage and QPixmap, they seem to offer the same functionality. When should I use a QImage and when should I use a QPixmap?
101
votes
13
answers
192k
views
How can I get the selected VALUE out of a QCombobox?
In Qt, I can get the selected text of a QComboBox by using the
combobox->currentText() method.
How can I get the selected value?
I searched for help but I couldn't find a method currentData() ...
99
votes
5
answers
159k
views
How to change the Title of the window in Qt?
How to change the title of the window in Qt? (Both for QDialog and QMainWindow.)