Qt: Remove the icon on the top left - qt

i want to remove the icon on the top left of a qt application. here is my main.cpp code
int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
engine.load(QUrl(QLatin1String("qrc:/main.qml")));
Receive receive;
QObject *topLevel = engine.rootObjects().value(0);
QQuickWindow *window = qobject_cast<QQuickWindow *>(topLevel);
// setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint);
QObject::connect(window,SIGNAL(sendUrltoC(QUrl)),&receive,SLOT(getText(QUrl)));
return app.exec();
}
if i uncomment the commented part it gives me an error. what should i do?

Related

How can I record a window using ffmpeg by id?

I want to get the id of the window by name using c++ or qml and record the specific screen using this id in ffmpeg.
ffmpeg -f x11grab -wid 0x6200012 -s 1920x1052 -r 30 -i :0.0+0,0
How can I do this?
it's not necessary to be the id, can be the offset-x and offset-y, I just want to record the window in any position.
I do not see that x11grab can record some screen by id as this answer indicates so as that answer points out one option is to use GStreamer:
gst-launch-1.0 ximagesrc xid=0x04000007 ! videoconvert ! autovideosink
How do I get the window id in Qt?
If QQmlApplicationEngine is used with Window or ApplicationWindow:
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QWindow>
int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
const QUrl url(QStringLiteral("qrc:/main.qml"));
QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
&app, [url, &engine](QObject *obj, const QUrl &objUrl) {
if (!obj && url == objUrl)
QCoreApplication::exit(-1);
if(QWindow *w = qobject_cast<QWindow *>(engine.rootObjects().first())){
qDebug() << w->winId();
}
}, Qt::QueuedConnection);
engine.load(url);
return app.exec();
}
With QQuickView
#include <QGuiApplication>
#include <QQuickView>
int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication app(argc, argv);
QQuickView view;
const QUrl url(QStringLiteral("qrc:/main.qml"));
view.setSource(url);
view.show();
qDebug() << view.winId();
return app.exec();
}
Qt Widgets:
#include "mainwindow.h"
#include <QApplication>
#include <QDebug>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
qDebug() << w.winId();
return a.exec();
}
Or in general you should access the QWindow and get the window id:
for(QWindow *w : QGuiApplication::allWindows()){
qDebug() << w->winId();
}
I found out the following:
ffmpeg -y -s 800x600 -f x11grab -window_id 0x3200008 -framerate 30 -i :11.0+0,0 -c:v libx264 -preset ultrafast -crf 40 output_select_window.mp4
Very important explanation:
-window_id = 'xwininfo' shows window_id if you select a window
-i :11.0+0,0 = 11 means and from in shell with `$echo $Display`.

SIGABRT in simple message box Qt program

Got an error running the following problem:
#include <QMessageBox>
#include <QApplication>
int main() {
QApplication app();
QMessageBox msgBox(QMessageBox::Critical,
QObject::tr("text1"),
QObject::tr("text2"),
QMessageBox::Ok);
msgBox.exec();
return 0;
}
The error is:
The program breaks at QMessageBox msgBox(...);
The call stack is:
EDIT: Even after i have added QApplication instance in XTerm window named qtcreator_process_stub i see the following:
QWidget: Must construct QApplication before a QWidget
The line
QApplication app();
doesn't create a QApplication object - it actually declares a function taking no arguments and returning a QApplication! This is sometimes known as the "most vexing parse".
To actually construct the application object, you need to provide the program's arguments:
QApplication app(argc, argv);
The full program is then
#include <QMessageBox>
#include <QApplication>
int main(int argc, char **argv) {
QApplication app(argc, argv);
QMessageBox msgBox(QMessageBox::Critical,
QObject::tr("text1"),
QObject::tr("text2"),
QMessageBox::Ok);
msgBox.exec();
return 0;
}

Having trouble drawing an image in Qt using QGraphicsScene

The code below loads an image using QLabel. The code uses: myLabel.setMask(pixmap.mask()); and it works as it should. The problem comes when I try and load an image using QGraphicsScene.
#include <QApplication>
#include <QLabel>
#include <QtGui>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QLabel myLabel;
QPixmap pixmap("/path/tomy/image.jpg");
myLabel.setPixmap(pixmap);
myLabel.setMask(pixmap.mask());
myLabel.show();
return app.exec();
}
In this code I am attempting to the same as above but using QGraphicsScene. The pixmap is loaded properly, after that I am not sure why the program is not working properly. Is it because there is no setMask() operation? Or is there an operation missing that is needed to make the image visible?
#include <QtGlobal>
#if QT_VERSION >= 0x050000
#include <QtWidgets>
#else
#include <QtGui>
#endif
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QPixmap pixmap("/path/tomy/image.jpg");
QGraphicsPixmapItem item( pixmap);
QGraphicsScene* scene = new QGraphicsScene;
scene->addItem(&item);
QGraphicsView view(scene);
view.show();
return a.exec();
}

create a multiple Mainwindow in QT

Thank you for going through this post. I have searched forums,blogs and SO, but could not get what I actually need.
I am experimenting on how to display multiple mainwindows. I am using a embedded hardware board. I have successfully ported QT lib on to it.
I have written a small program.
mainwindow.cpp
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
main.cpp
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow text_plane;
text_plane.setWindowFlags(Qt::Window | Qt::FramelessWindowHint);
text_plane.setStyleSheet("background-color: Black;");
text_plane.show();
a.exec();
return a.exec();
}
The above code displays one window only.
Even if I create a Mainwindow w1 after text_plane.show() like
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow text_plane,w1;
text_plane.setWindowFlags(Qt::Window | Qt::FramelessWindowHint);
text_plane.setStyleSheet("background-color: Black;");
text_plane.show();
w1.setWindowFlags(Qt::Window | Qt::FramelessWindowHint);
w1.setStyleSheet("background-color: Yellow;");
w1.show();
a.exec();
return a.exec();
}
Now only the w1 window is shown. What about the text_plane window ?? how to get that back.
Can anyone help me out here to make this understand.
Thank you
First of all, I wonder, what are you trying to achieve here:
a.exec();
return a.exec();
You need to call this method only once, you know.
Second of all, both of your windows are shown (you can see it in a taskbar), but, since you set Qt::FramelessWindowHint, one of them is drawn on top of the other. You can split them by using move (or something like it):
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
MainWindow w, w1;
w.setWindowFlags(Qt::Window | Qt::FramelessWindowHint);
w.setStyleSheet("background-color: Black;");
w.show();
w1.setWindowFlags(Qt::Window | Qt::FramelessWindowHint);
w1.setStyleSheet("background-color: Yellow;");
w1.show();
w.move(0, 0);
w1.move(100, 100);
return app.exec();
}

Slot not called for QSplashScreen

I'm trying to show a start-up image using QSplashScreen and I want to show the image for about 2 seconds.
int main(int argc, char *argv[]) {
QApplication a(argc, argv);
QPixmap pixmap(":/images/usm.png");
QSplashScreen splash(pixmap);
splash.show();
splash.showMessage("Loading Processes");
QTimer::singleShot(2000, &splash, SLOT(close()));
MainWindow w;
w.show();
splash.finish(&w);
return a.exec();
}
But this is not working. QSplashScreen appears for some milliseconds and then disappears. Tried to modify the time period but it seems like the QSplashScreen object is not connected to slot. What's the problem and how to avoid it?
The problem with your code is that the timer is not blocking the execution so the splash screen has already closed with the splash.finish(&w) call. What you need is a sleep. You could use a QWaitCondition like this:
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QSplashScreen splash(QPixmap(":/images/usm.png"));
splash.show();
splash.showMessage("Loading Processes");
// Wait for 2 seconds
QMutex dummyMutex;
dummyMutex.lock();
QWaitCondition waitCondition;
waitCondition.wait(&dummyMutex, 2000);
MainWindow w;
w.show();
splash.finish(&w);
return a.exec();
}
The disadvantage of this approach is that you are blocking the execution. If you do not want to block it then you can simply remove the splash.finish(&w) call:
int main(int argc, char *argv[]) {
QApplication a(argc, argv);
QPixmap pixmap(":/images/usm.png");
QSplashScreen splash(pixmap);
splash.show();
splash.showMessage("Loading Processes");
QTimer::singleShot(2000, &splash, SLOT(close()));
MainWindow w;
w.show();
return a.exec();
}
This code should work:
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QSplashScreen splash(QPixmap(":/images/usm.png"));
splash.showMessage("Loading Processes");
splash->show();
QMainWindow w;
QTimer::singleShot(2000, splash, SLOT(close()));
QTimer::singleShot(2500, &w, SLOT(show()));
return a.exec();
}

Resources