As far as I can tell the issue is that QPointF provides a constructor which takes a QPoint. When you do a static_cast the compiler tries to call QPointF(MyPoint&) and it sees two ways to create a QPointF from MyPoint: Use the constructor taking a QPoint, by converting MyPoint to...
QFileInfo doesn't have a method specific for that, but here you can find a simple implementation subclassing QFileInfo and implementing this new method QString QFileInfoHumanSize::size_human() { float num = this->size(); QStringList list; list << "KB" << "MB" << "GB" << "TB"; QStringListIterator i(list); QString unit("bytes"); while(num >= 1024.0 && i.hasNext())...
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....
...\user.h(13) : error C2065: 'Read' : undeclared identifier Looks like Read is not known in user.h. Maybe date.h or book.h are including user.h as well? (circular references) Using prototype classes can help to prevent this....
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...
c++,qt,background-image,qframe
This code works for me (tested under MacOS/X 10.10.3, using Qt 5.5.0-beta; I'd expect it to work under any Qt version 4.5.0 or higher though): main.h: #ifndef main_h #define main_h #include <QFrame> #include <QPixmap> class MyFrame : public QFrame { public: MyFrame(QWidget * parent); virtual void paintEvent(QPaintEvent * e); private:...
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...
c++,qt,user-interface,qwidget,qtablewidget
Read logs! I'm sure you have a respective warning. You are assigning same layout to two different widgets. Once layout is assigned to a widget, it is owned by this widget forever. You need create separate layout for each widget. I recommend to split this onto couple methods. One is...
python,qt,qt-creator,qtablewidget
Use table.horizontalHeader().setSectionResizeMode(...) (or setResizeMode in older Qt versions) with appropriate resize mode.
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); }); ...
The * operator is usually greedy in Qt Regexp. You can change this by calling setMinimal(true) Greedy regexps try to consume as much as possible, and therefore behave exactly as you are experiencing. Minimal Regexps try to match as little as possible. This should solve your problem, as the matching...
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...
In Opciones.cpp you haven't declared filaSeleccionada to be scoped within the Opciones class. Declare it this way: void Opciones::filaSeleccionada(const QModelIndex & current, const QModelIndex & previous){ } What you've done in your code is to declare a new free function, filaSeleccionada. The compiler has no problem with this, as it...
python,qt,user-interface,pyqt,py2app
This is happening because py2app would not be able to find files specified through string paths in the code. It will not include those files in the binary. You can do one of two things to solve your problem. 1) You have to convert your .ui file to .py file...
The only way to use that idiom while still keeping your code understandable is if your function returns an object that is convertible to bool in a way that true indicates that you want to take the branch and false means that you do not care about it. Anything else...
I think you forget to append moc and resources to your executable use qt5_wrap_cpp() for mocs use qt5_add_resources() for resources. Then you must append vars to add_executable check out this link. ...
If aborted, QNetworkReply::error() should return QNetworkReply::OperationCanceledError, which means: the operation was canceled via calls to abort() or close() before it was finished. ...
c++,osx,qt,fsevents,file-watcher
The problem was unrelated to this code. The pointer works fine but his object was lost.
c++,qt,qt-creator,signals-slots,qtableview
The signal slot connection has failed since table->selectionModel() has returned null. If you set the model for your table before making signal slot connection, table->selectionModel() will return a valid model, making the signal slot connection successful....
Of course, and it's quite easy. You can have a look at the ui_mainwindow.h at the debug/release dir. I prefer setting layouts for widgets in QtDesigner to the code. It's something like this: //set layout programatically auto layout = new QHBoxLayout(ui->centralWidget()); //or if you have set horizontalLayout in Qt Designer...
javascript,qt,focus,qml,qtquick2
Bind highlightLine.visible to root.activeFocus so the highlight only shows when the checkbox gains active focus: Rectangle { id: highlightLine //... visible: root.activeFocus } The active focus can be set in many ways. For example, when user clicked the checkbox: MouseArea{ id: bodyArea onClicked: { //... root.forceActiveFocus(); //set root's active focus...
c++,qt,hash,unordered-map,std-pair
I don't know anything about QT, but if QHash is anything like unordered_map, then the issue is where you're using operator[]. That function will insert a default-constructed value for a given key if it doesn't exist. In order to do that, the value-type must be default constructible, and: std::pair<const ParticipantNode&,...
Dev-C++ is based on mingw, so you should install Qt compiled for mingw on Windows. Then indeed you should use qmake to generate Makefiles. For compilation you should use the make utility provided by mingw distribution shipped with Dev-C++ (the name of this utility might not be exactly 'make' in...
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); ...
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...
You can totally do this. You do not actually need these headers (using them is just usefull) - all you really need is to declare all objects (types, functions, variables) you are actually using. So, if you have a lot of headers, but use, say, only one function, all you...
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.
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...
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); ...
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...
python,qt,pyside,enthought,canopy
Usually this error means that PySide is either unable to find the Qt DLLs, or the ones it did find are not the right version and do not have some of the expected symbols. Do you have some other set of Qt libraries on your system in the PATH somewhere?...
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....
It doesn't work. That way you simply suppress the warning by making the situation harder to analyze. The behavior is still undefined.
Use lastKey: const Key & QMap::lastKey() const Returns a reference to the largest key in the map. This function assumes that the map is not empty. This executes in logarithmic time. This function was introduced in Qt 5.2. As in: qreal last = myMap.lastKey(); ...
The problem is that &QSerialPort::error is ambiguous: There's the signal you're trying to connect to: QSerialPort::error(QSerialPort::SerialPortError) But then there's also a getter with the same name: QSerialPort::error() That's unfortunate design of the QSerialPort class (QProcess has the same problem), and might be fixed in Qt 6, but not before that,...
qt,user-interface,python-3.x,dialog,qt-creator
use setModal() like so; dialog.setModal(1); Or; dialog.setModal(true); ...
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...
It turns out you just need to copy plugins directory from your Qt installation folder to your app folder.
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...
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...
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....
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.
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");...
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...
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...
File names are case sensitive. Try qmake magread.pro Or just this, if directory name is also magread or if there is just one .pro file in current directory: qmake ...
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...
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...
The transform property of Item is a list, so you can apply multiple rotations: import QtQuick 2.3 import QtQuick.Window 2.2 Window { visible: true width: 200 height: 200 Rectangle { width: 100 height: 100 anchors.centerIn: parent color: "red" transform: [ Rotation { origin.x: 30; origin.y: 30; axis { x: 0;...
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); ... } ...
c++,qt,app-bundle,cfurl-encoding
You need to link with the CoreFoundation framework. You can add the following to your qmake project: LIBS += "-framework CoreFoundation" ...
I had the same problem. Adding these lines to build.xml file solved it: <property name="aidl" location="${sdk.dir}/build-tools/22.0.1/aidl${exe}" /> <property name="aapt" location="${sdk.dir}/build-tools/22.0.1/aapt${exe}" /> <property name="dx" location="${sdk.dir}/build-tools/22.0.1/dx${exe}" /> <property name="zipalign" location="${sdk.dir}/build-tools/22.0.1/zipalign${exe}" /> ...
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;...
You're trying to use QComboBox's internal model as source model for proxy. This is not going to work because QComboBox owns its internal model and when you call QComboBox::setModel, previous model is deleted (despite you reset its parent). You need to create a separate source model. Conveniently, you can use...
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....
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...
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...
I think my problem was related to the style in which I was connecting the signal and slot. I found this great post that walks you through the new style. I created a few variables before the MyLineEdit's constructor. Then I used those variables in the tab_event function. Then I...
There is need to edit Q_INIT_RESOURCE argument. int main(int argc, char *argv[]) { Q_INIT_RESOURCE(mdi); ...
Had an error in my paint-Routine for SudokuFieldWidget which caused this misbehaviour... m_markerOverlay->setGeometry( this->geometry() );
c++,sql,database,qt,postgresql
You are calling the wrong version of setQuery. This only works with db which have the default name. In your case, you need to call void QSqlQueryModel::setQuery(const QString &query, const QSqlDatabase &db): model.setQuery(QString("SELECT * FROM users WHERE login=%2").arg(Vars::strUserLogin) , db); ...
qt,qml,qt-creator,qtquick2,qt-quick
You need to add them to your .pro file (if I'm not wrong it's enough to append them to DISTFILES).
You can use a GridLayout instead of building a grid by means of ColumnLayout and RowLayout. By using the GridLayout, what you want is already guaranteed by the component. Here is a full example from which you can start: import QtQuick 2.3 import QtQuick.Window 2.2 import QtQuick.Controls 1.2 import QtQuick.Layouts...
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...
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;...
I have developed a few Qt applications and to this day no knowledge whatsoever about qml. It definitely is the new way because it is newer than what you're after but if everything will be done in qml in Qt 6 or 7 I have no idea. So to answer...
Easy way: comboBox->setIconSize(QSize(100, 24)); comboBox->addItem(lineIcon, ""); comboBox->addItem(dotLineIcon, ""); comboBox->addItem(dashLineIcon, ""); ... Correct way: comboBox->setItemDelegate(...); ...
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...
This is probably the most simplistic example I can think of that will work for MSVC. I don't imagine it would be too much more different for QT Creator. #include <sapi.h> #include <sphelper.h> #include <conio.h> int main(int argc, char *argv[]){ HRESULT hr = S_OK; CComPtr<ISpVoice> cpVoice; ::CoInitialize(NULL); hr = cpVoice.CoCreateInstance(CLSID_SpVoice);...
Having hundreds of labels in the application and layouting them in your scroll area will cost you much memory and performance. From the other hand Qt has the number of dedicated classes to handle multiple items in a scroll area such as: QTableWidget, QListWidget, QTableView etc. All these classes designed...
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 ...
c++,qt,opengl,transform-feedback
It turned out that I never actually extended my class to use QOpenGLFunctions_4_3_Core, and it was instead just QOpenGLFunctions. Changing it to the former solved the problem.
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.
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 =...
c++,qt,user-interface,inheritance,objective-c++
You have to add the line #include "ui_cgenericproject.h" to the CEisProject.cpp file. The CGenericProject.h file is included in CEisProject.h, but CEisProject.h does not have access to CGenericProject.cpp. In the header of your base class you have a only forward declaration of Ui::CGenericProject, and you include its file in the .cpp....
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...
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...
Issue is in statement QObject::connect(console_backend, SIGNAL(console_backend ->readyReadStandardOutput()), this, SLOT(this->receiveConsoleBackendOutput())); It should be QObject::connect(console_backend, SIGNAL(readyReadStandardOutput()), this, SLOT(receiveConsoleBackendOutput())); ...
On OS X, the name of a file at the level of the APIs is different from the display name that is shown to the user in the Finder, open and save panels, etc. At the level of the APIs, file names simply can't contain slashes. They are reserved for...
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...
I've done that few years back. Should be working fine. //determinge the maximum width required to display all names in full int max_width = 0; QFontMetrics fm(ui.comboBoxNames->font()); for(int x = 0; x < NamesList.size(); ++x) { int width = fm.width(NamesList[x]); if(width > max_width) max_width = width; } if(ui.comboBoxNames->view()->minimumWidth() < max_width)...
The reason the UI isn't updating is that you never cede control to the event loop, so the main thread doesn't have a chance to update the UI until after your code has executed. There's two possible solutions here: Move your existing code to a background thread that fires a...
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());...
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...
If I got your problem right, you just have minutes variable instead of a seconds. Just change "hh:mm:mm" to "hh:mm:ss" void noheatmode::setCurrentTime() { QTime time = QTime::currentTime(); QString sTime = time.toString("hh:mm:ss"); ui->tempTimeNoHeatMode->append(sTime); } ...
It was a problem with the database and not the Qt application, the connection refused if a password was used.
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...
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...
Does the thread affinity has any impact on the class data? No, a QObject's thread affinity only controls which thread it's slot and event handlers run in. Does the class data becomes a thread data? Class data means class static data members - that can't possibly be affected by...
qt,python-3.x,qt-creator,pyqt5
When you call a method as object.method(argument1, ...) then object is implicitly passed to the method as the first argument. So with your current code, the line self.setupUi(self,QMainWindow) is actually passing three arguments to the method setupUi. They are self, self (again) and QMainWindow. You might want to read this:...
I think that you're confused by the cooperative multitasking exhibited by typical event driven applications, with their run-to-completion event handlers. This is how WIN16, GEM and other such platforms appeared to multitask with no context switches at all. I'll attempt to clear this confusion after exposing the necessary background to...