Menu
  • HOME
  • TAGS

Qt app receives HUP signal unexpectedly when forked to background

Tag: qt,signals,fork,daemon,signals-slots

I have built a Qt app which upon receipt of the HUP signal shuts down nicely (setup like this how to get signals into Qt). This works great under Red Had 6, but when I run this app under Ubuntu 14 my app receives the HUP signal immediately (after forking to run in the background) and then shuts down - even though I didn't send a HUP. Furthermore, this ONLY happens when my app forks and runs in the background - if I run my app in the foreground it does not receive the hup unexpectedly.

Is there some other reason that might cause it to receive a HUP signal when daemonized? (And why under one distro but not the other)

Best How To :

When daemonizing (forking), the parent process issues a HUP signal upon exit. For some reason on Red Hat this signal doesn't hit child process until much later. On Ubuntu the signal hits the child quickly (or perhaps Ubuntu holds the signal for the child).

Solution is to confirm parent process has terminated and then hook into the HUP signal.

Context Pointer Lost in FSEventStreamCreate Callback (c++)

c++,osx,qt,fsevents,file-watcher

The problem was unrelated to this code. The pointer works fine but his object was lost.

load a thumbnail on QListWidget with reduced resolution

image,qt,qlistwidget,qlistwidgetitem

Use QImage first to scale the image and construct the icon from the resulting pixmap. QSize desiredSize; Qimage orig(filesToLoad[var]); Qimage scaled = orig.scaled( desiredSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); QListWidgetItem *listItem = new QListWidgetItem(QIcon(Qpixmap::fromImage(scaled)),filename); It is very common to store the presized image too on the disk, to avoid the two step conversion...

change QDir::rootPath() to program running path?

c++,qt

QCoreApplication::applicationDirPath() returns the exact directory path of your app, for example H:/programs if your app path is H:/programs/ftpserver.exe so if you modify that QString you can get the root dir. For example: QString rootPath = QCoreApplication::applicationDirPath(); rootPath.chop(rootPath.length() - 3); //we leave the 3 first characters of the path, the root...

Align horizontalcenter in Column

qt,qml,qtquick2,qt-quick

I suppose you can use anchors.horizontalCenter for all the child items to align them with the horizontalCenter of the column given that the column has an id you can refer to.

C++ & Qt: Random string from an array area

c++,arrays,string,qt,random

You should use the random header. #include <random> std::default_random_engine generator; std::uniform_int_distribution dist(0, 5); int StringIndex = dist(generator); std::string ChosenString = characters[StringIndex]; The above will generate a random index into your array. If you want to limit the range, change the constructor of dist, for example (dist(0,2) would only allow for...

Using QSimpleXmlNodeModel and QTreeView

c++,qt

There is an example delivered with Qt. Take a look at xmlpatterns/filetree example. It is not that easy as with some other models. You have to implement these abstract methods: QUrl QAbstractXmlNodeModel::documentUri(const QXmlNodeModelIndex &) const QXmlNodeModelIndex::NodeKind QAbstractXmlNodeModel::kind(const QXmlNodeModelIndex &) const QXmlNodeModelIndex::DocumentOrder QAbstractXmlNodeModel::compareOrder(const QXmlNodeModelIndex &,const QXmlNodeModelIndex &) const QXmlNodeModelIndex QAbstractXmlNodeModel::root(const...

How to add a gif image in the statusbar Qt [closed]

c++,qt

You can add a QLabel, with a QMovie in it. QLabel label; QMovie *movie = new QMovie("animations/fire.gif"); label.setMovie(movie); movie->start(); You can then add the label to the using QStatusBar::addWidget() like so: statusBar()->addWidget(&label); ...

How can I make a QTextEdit widget scroll from my program

c++,qt

Here is what I found as a suitable solution: The vertical scrollbar may be accessed using the QTextEdit::verticalScrollBar() method. Scrollbars have a triggerAction() method to conveniently simulate user interaction with the buttons and the slider. The available actions are defined in QAbstractSlider. So the resulting code is only a single...

Change attribute value of an XML tag in Qt

c++,xml,qt

I guess, but I think your XML is only present in your memory. You have to trigger somethink like tsFileXml.WriteToFile(filename) to store your changes to a file on your filesystem.

Qstring error. Saving from Textpool to string

c++,qt,qstring

http://doc.qt.io/qt-4.8/qlineedit.html#text-prop textChanged is a signal that you can send when the text changes Use QString text() const instead Another useful method: modified : bool to check if the text was modified by the user Update to answer additional comment questions: It is best to declare all variables as private. Add...

Adding an image to the Qt toolbar area

c++,qt,toolbar

The QToolbar already contains all the functionality you need. Simply user the addWidget(QWidget* method and supply a pointer to the widget (your label). QLabel* label = new QLabel(); label->setPixmap(QPixmap("...")); this->ui.toolbar->setWidget(label); ...

Update bindings to var properties in QML

qt,qml

Actually, the page does say how to work around this: If the onCompleted handler instead had "car = new Object({wheels: 6})" then the text would be updated to say "The car has 6 wheels", since the car property itself would be changed, which causes a change notification to be emitted....

std::ostream to QString?

c++,qt,exception

You can use an std::stringstream as follows: std::stringstream out; // ^^^^^^ out << "Error in void Cat::eat(const Bird &bird): bird " << bird << " has negative weight" << std::endl; throw(QString::fromStdString(out.str())); // ^^^^^^^^^^^^^^^^^^^^^^^^^^ Specifically, the std::stringstream::str member function will get you an std::string, which you can then pass to the...

Deploying to Android results in file not found after adding QtQuick Controls

android,qt,deployment,qml,qt5.4

When deploying the application, androiddeployqt will copy a bunch of files which terribly fails on Windows when source or destination paths become longer than 260 characters (yeah, that's a "known feature"). Keeping the Qt installation and the project directory as top level as possible helps to reduce the path lengths...

Return const reference to local variable correctly

c++,qt

It doesn't work. That way you simply suppress the warning by making the situation harder to analyze. The behavior is still undefined.

How to change the opacity of Qt MainWindow?

qt,qmainwindow

The below works for me most of times (as long as we can run in stylesheet override problem with other ways). Consider change the last component of rgba to less than 255 for making it semi-transparent. widget->setStyleSheet("background-color: rgba(255, 255, 255, 255);"); Mind that child widgets may inherit the transparent background...

Customizing QDateEdit style

c++,qt

It comes close to the image you've posted: QDateEdit { background-color: white; border-style: solid; border-width: 4px; border-color: rgb(100,100,100); spacing: 5px; } QDateEdit::drop-down { image: url(:/new/myapp/cbarrowdn.png); width:50px; height:15px; subcontrol-position: right top; subcontrol-origin:margin; background-color: white; border-style: solid; border-width: 4px; border-color: rgb(100,100,100); spacing: 5px; } Maybe the key-word here is "sub-control". The arrows...

How to differentiate a QNetworkReply is aborted or not?

c++,qt,networking

If aborted, QNetworkReply::error() should return QNetworkReply::OperationCanceledError, which means: the operation was canceled via calls to abort() or close() before it was finished. ...

QT-FTP Upload Error

c++,qt,ftp,qnetworkreply

I can't get, why do you use QNetwork instead awesome QFtp module, that provides all necessary for work with ftp? QFtp *ftp = new QFtp(parent); ftp->connectToHost("f13-preview.125mb.com"); ftp->login("1896230", "mypassword"); and then use QFtp::put. That's all you need....

Loading animated gif data in QMovie

json,qt,pyside,animated-gif

This looks like a PySide bug, as the same code works perfectly fine in PyQt. The bug seems to be in the QMovie constructor, which does not read anything from the device passed to it. A work-around is to set the device explicitly, like this: import sys from PySide import...

Qt can't assign value to QLabel

c++,qt

The issue is with following signal slot connection. QObject::connect(calculate, SIGNAL(clicked()), &prog, SLOT(results->setNum(value(*spinner));)); You are trying to connect the clicked() signal of calculate button to results->setNum(value(*spinner)); slot of prog. But results->setNum(value(*spinner)); is not actually a slot. A slot is simply a method in a class that inherits QObject. Method should be...

Must compile Opencv with Mingw in order to use in QT under Winodws?

qt,opencv,mingw

You can compile it with Visual Studio as well. The opencv includepaths already have the opencv2 part of it. So the correct includepath would only be: C:\\opencv2.4.11\\opencv\\build\\include ...

How to pass QString variable to QFile?

qt,qstring,qfile

QString selected = model2->filePath(index); does not set the variable in the (maybe same named) member OptionsDialog::selected. This creates a new local variable. If you have a member variable called selected then you should use it like this: void OptionsDialog::getData(const QModelIndex &index) { selected = model2->filePath(index); ... } ...

How to avoid user to click outside popup Dialog window using Qt and Python?

qt,user-interface,python-3.x,dialog,qt-creator

use setModal() like so; dialog.setModal(1); Or; dialog.setModal(true); ...

How to set User Agent in QtWebEngine QML application

qt,qml,qt5,user-agent,qtwebengine

I'm interested in using QtWebEngine too. And I can suggest you use QtWebEngine developers Trello. As you can see in Todo for 5.5 this is currently under development and may be done in 5.5....

Rotating a Label In Qt with Python

python,qt

Not 100% sure what you're trying to achieve, but rotating the image / pixmap and leaving the label's paintEvent unchanged seems easier: # load your image image = QtGui.QPixmap(_fromUtf8(":/icons/BOOM_OUT.png")) # prepare transform t = QtGui.QTransform() t.rotate(45) # rotate the pixmap rotated_pixmap = pixmap.transformed(t) # and let the label show the...

How to manipulate multiple Folders/Dir in QT?

c++,qt,qmediaplayer,qdir,qfileinfo

If i understood correctly you want something like this: My code is a bit rough but you can use it as starting point: -MainWindow.h: #ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> #include <QComboBox> namespace Ui { class MainWindow; } class MainWindow : public QMainWindow { Q_OBJECT public: explicit MainWindow(QWidget *parent =...

Bash ERR signal not trapped in procedures?

bash,signals

Quoting man bash on FUNCTIONS: the ERR trap is not inherited unless the -o errtrace shell option has been enabled. So, just add set -o errtrace to the script and it starts working....

Plotting random signal on circle

matlab,plot,signals,circle

You need to add "noise" to the radius of the circle, roughly around r=1: th = linspace( 0, 2*pi, N ); %// N samples noise = rand( 1, N ) * .1; %// random noise in range [0..0.1] r = 1+noise; %// add noise to r=1 figure; plot( r.*cos(th), r.*sin(th)...

Updating ac value for Qtimer

qt,user-interface,adc

Hopefully this will get you started - it creates a timer which times out every 1000 milli seconds. The timer's timeout signal is connected to the same slot that your PushButton1 is connected to - starti2c. QTimer *timer = new QTimer(this); connect(timer, SIGNAL(timeout()), this, SLOT(starti2c())); timer->start(1000); That code should be...

What does QHeaderView::paintSection do such that all I do to the painter before or after is ignored

c++,qt,qpainter,qheaderview

It is obvious why the first fillRect doesn't work. Everything that you paint before paintSection is overridden by base painting. The second call is more interesting. Usually all paint methods preserves painter state. It means that when you call paint it looks like the painter state hasn't been changed. Nevertheless...

Recursive signal call using kill function

c,signals

Historically, lots of details about how signals work have changed. For instance, in the earliest variant, the processing of the signal reverted to default when the handler was called, and the handler had to re-establish itself. In this situation, sending the signal from the handler would kill the process. Currently,...

Pro file directive: copy target to folder at build step

qt,qt5

Create DestDir.pri in folder, where all of your projects located. Insert next code: isEmpty(DESTDIR) { CONFIG(debug, debug|release) { DESTDIR=$$PWD/Build/Debug } CONFIG(release, debug|release) { DESTDIR=$$PWD/Build/Release } } Include DestDir.pri to each pro file: include(../DestDir.pri) You can change DESTDIR variable to your path or set this variable via qmake command line utils...

QODBCResult::exec: Unable to execute statement: "[Microsoft][ODBC SQL Server Driver]COUNT field incorrect or syntax error

c++,sql-server,qt,tsql,odbc

The problem turned out to be the syntax, I changed it to query.prepare("{CALL add_syllabus_line (:teacher_name, :subject_name, :temporary_name, :type_name, :activity_name, :min_score, :max_score, :max_score_exists, :evaluation_by_exam)}"); QComboBox *combo = static_cast<QComboBox*>(table->cellWidget(i,0)); query.bindValue(":teacher_name", teacherName); query.bindValue(":subject_name", "Физика"); query.bindValue(":temporary_name", ratingName); query.bindValue(":type_name", combo->currentText());...

QT Combo Box of Line Pattern

c++,qt,qcombobox

Easy way: comboBox->setIconSize(QSize(100, 24)); comboBox->addItem(lineIcon, ""); comboBox->addItem(dotLineIcon, ""); comboBox->addItem(dashLineIcon, ""); ... Correct way: comboBox->setItemDelegate(...); ...

How can I override the member of (->) operator of a base class

c++,qt,inheritance,overloading,operator-keyword

As I eventually realised above, this isn't possible. The operator ->() has to return the type upon which it is acting, and for that reason it can't be used as a virtual function.

QDateTime Conversion

qt,qdatetime

Your date string does not include a time, while you mentioned that you want one, this will fail at least in Qt 5.4 . I don't know though why you get the epoche outputed, maybe that is dependant on your Qt version. Your date format is also locale dependent. See...

Linux : pthread_cond_signal() is not working inside a Signal Handler()

c++,c,linux,signals,posix

In Signal handler there are only a very limited number of syscalls allowed. see man 7 signal http://man7.org/linux/man-pages/man7/signal.7.html My Suggestion is, to be on the safe side, the so called "self pipe trick". http://man7.org/tlpi/code/online/diff/altio/self_pipe.c.html You could start a thread which runs a select Loop on the self pipe and call...

Is there a way to prevent Qt slider dragging beyond a value?

qt,qslider

Use this class and just set setRestrictValue() that is the minimum value that user can drag the slider slider.h #ifndef SLIDER_H #define SLIDER_H #include <QSlider> class Slider : public QSlider { Q_OBJECT public: Slider(QWidget * parent = 0); ~Slider(); void setRestrictValue(int value); private slots: void restrictMove(int index); private: int m_restrictValue;...

Repeat state on mouse click QML

qt,qml,qtquick2

States are a way to represent different property configurations for a given Item. Each State has its unique set of values for the properties defined inside the specific Item. Transitions are a way to add animations to an Item when the current State changes to another State. They can be...

Id in database using qt

database,qt,sqlite

The method you're looking for is QSqlQuery::lastInsertId(). To quote the documentation: Returns the object ID of the most recent inserted row if the database supports it. An invalid QVariant will be returned if the query did not insert any value or if the database does not report the id back....

Unable to connect to mariadb database server with qt 4.8.5 and Ubuntu 12.04

mysql,qt,ubuntu,mariadb

It was a problem with the database and not the Qt application, the connection refused if a password was used.

How can I have an animated system tray icon in PyQt4?

python,qt,pyqt,pyqt4,system-tray

Maybe something like this. Create QMovie instance to be used by AnimatedSystemTrayIcon. Connect to the frameChanged signal of the movie and call setIcon on the QSystemTrayIcon. You need to convert the pixmap returned by QMovie.currentPixmap to a QIcon to pass to setIcon. Disclaimer, only tested on Linux. import sys from...

connecting signals and slots with different relations

c++,qt,connect,signals-slots

You need to create new slot for that purpose. But in C++ 11 and Qt 5 style you can use labmdas! It is very comfortable for such short functions. In your case: connect(ui->horizontalSlider, &QSlider::sliderMoved, this, [this](int x) { this->ui->progressBar->setValue(x / 2); }); ...

Copy text and placeholders, variables to the clipboard

c++,qt,clipboard

You're not using the function setText correctly. The canonical prototype is text(QString & subtype, Mode mode = Clipboard) const from the documentation. What you want to do is assemble your QString ahead of time and then use that to populate the clipboard. QString message = QString("Just a test text. And...

QEvent ownership

c++,qt,memory-management

event = &stackevent; //valid ?? Usually that's not safe, but in this case it's valid, because the function notify won't return, untill the event is handled (or not) by someone (it means that stackevent will be "alive" during this operation). delete heapevent; //valid? or lost ownership? Yap, that's valid...

Sorting based on the rules set by a string variable

c++,qt,sorting,c++11

You can make a map between their choice and a functor to sort by, for example using SortFun = bool(*)(Hotel const&, Hotel const&); std::map<char, SortFun> sorters { {'s', [](Hotel const& lhs, Hotel const& rhs){ return lhs.stars < rhs.stars; }}, {'f', [](Hotel const& lhs, Hotel const& rhs){ return lhs.freeRoomCount < rhs.freeRoomCount;...

QWidget.paintevent() vs QLabel.setPixmap()

qt,qwidget,qlabel

I would override MonitoringWidget::paintEvent() and then use the monitored widget's QWidget::render() to render the monitored widget into the MonitoringWidget. This should roughly be equivalent to what the widget being monitored itself will do when it receives paint events. Also you probably need some link between the monitored widget and the...

How to align GUI elements like this? Qt, C++

c++,qt

Here is the most direct, but hardcoded way. #include "widget.h" #include <QLabel> #include <QFont> Widget::Widget(QWidget *parent) : QWidget(parent) { QSize frameSize = this->frameGeometry().size() - this->geometry().size(); this->resize(frameSize + QSize(250, 125)); QLabel * label = new QLabel(this);// parenting instead of layouts label->resize(130, 32); label->move(60, 40); QFont f = label->font(); f.setPointSize(16); label->setFont(f); label->setText("Sample");...

How can I wrap text in QGraphicsItem?

qt,text,word-wrap,qgraphicsitem

You did not specify Qt version but try: void QGraphicsTextItem::setTextWidth(qreal width) Sets the preferred width for the item's text. If the actual text is wider than >the specified width then it will be broken into multiple lines. If width is set to -1 then the text will not be broken...