I would like to add 3 items to statusbar. Shouldn't each be in its own label?
Is that possible? When I tried to add a second label, it gave me an error.
File mainwindow.h,
QLabel *m_statusLabel;
QLabel *m_pointLabel;
File mainwindow.cpp,
statusBar()->addWidget(m_statusLabel);
statusBar()->addWidget(m_pointLabel);
It works perfectly with one label, but when I add a second, then I get the following.
Starting C:\Users\Jansu\Desktop\cpp-praktikum05-alus\Joonistamine-build- desktop\src\bin\Joonistamine.exe...
ASSERT: "d" in file ..\..\include/QtCore/../../src/corelib/tools/qscopedpointer.h, line 112
Invalid parameter passed to C runtime function.
Invalid parameter passed to C runtime function.
C:\Users\Jansu\Desktop\cpp-praktikum05-alus\Joonistamine-build- desktop\src\bin\Joonistamine.exe exited with code -1073741819
I found the problem. I forgot to create QLabels, so I added this:
m_statusLabel = new QLabel(this);
m_pointLabel = new QLabel(this);
Related
Hey guys I'm new in c++ wxwidgets programming.
I would like to know the easiest way to put an image into a button.
I tried :
button1 = new wxBitmapButton(side_panel, wxID_ANY, wxBitmap("image.png",wxBITMAP_TYPE_PNG), wxPoint(150,30), wxSize(30, 30),wxBORDER_NONE);
But I always get the same error:
If you expand the error dialog you see, you should see more information about the error, but my guess is that the image simply can't be found. You should check that the file image.png indeed exists in the current working directory of your program, i.e. the directory that you run it from, assuming you don't change it later.
You should also actually check for errors in your programs, even simple ones, i.e.
wxBitmap bmp("image.png");
if (!bmp.IsOk()) {
... handle the error somehow instead of blithely using an invalid bitmap ...
}
Say I have a tabwidget in my ui file
this is how im adding tabs right now:
QPlainTextEdit *tab = new QPlaintextEdit;
int index = ui->tabWidget->addTab(tab, "changeme");
Now I'm wondering if it's possible to change the name of the tab on the go,
for example when subclassing QPLainTextEdit in a class and connecting a signal to it when the text changes then i'd like to add a little star to the tab to indicate that the file has been modified, is it even possible?
QTabWidet::setTabText does what you want.
E.g:
ui->tabWidget->setTabText(index, "new text");
I am struggling with adding a custom icon to a QToolButton.
I have a resource file(properly under RESOURCES in the .pro file):
myResourceFile.qrc containing
/images
ICON_TEST.png
and code
dragButton = new QToolButton(this);
QString resourcePath = ":/images/ICON_TEST.png";
QPixmap pixIcon(resourcePath); //THE LINE THAT GIVES THE ERROR!
dragButton->setIcon(QIcon(pixIcon));
I get the error:
no match for call to QPixmap(QString &)
How do I pass the proper path to the QPixmap object and then the object to setIcon()?
edit:
Just confirmed that the .png file exists and is recognized by Qt:
File exists - true ":/images/ICON_TEST.png"
with:
qDebug()<<"File exists -"<<QFileInfo(":/images/ICON_TEST.png").exists()<<" "<<
QFileInfo(":/images/ICON_TEST.png").absoluteFilePath();
EDIT WITH SOLUTION: below as answer
Question remains, why this happened? The variable pixIcon is declared in the .h file of the class as:
QPixmap pixIcon;
and assigned a value in the constructor:
pixIcon(resourcePath);
Which to me seems to be almost equivalent to doing it in one line.
This was on Windows Vista with Qt Creator 2.0.
For some reason, when doing everything in one line it worked as it should have:
dragButton->setIcon(QIcon(QPixmap(resourcePath)));
Hopefully a very quick question. In one of my functions I want to generate an 'x' number of tabs for a QTabWidget during run-time ('x' provided by user). I know I have to use the addTab function for the QTabWidget (correct me if I'm wrong), but I am unsure as to how I am supposed to use it. The qt documentation was unclear to me.
I have tried the following command to add only 1 tab as a test, but it caused the program to crash:
ui->checkBoxTabArea->addTab(ui->checkBoxTabArea,"tab2");
Since I am obviously wrong, can somebody help me use this function? I feel like I am just passing the wrong arguments to addTab.
Edit: checkBoxTabArea already has 1 tab when the program starts up (if this is any help).
If you take a look at the documentation, the addTab function says this :
int QTabWidget::addTab ( QWidget * page, const QString & label )
Adds a tab with the given page and label to the tab widget, and
returns the index of the tab in the tab bar.
So the argument you pass should not be the TabWidget you want to add the tab to, rather it should be the widget you want to add as the tab.
What you should do is something like :
QLabel *myLabel = new QLabel("Hello World", this);
ui->checkBoxTabArea->addTab(myLabel, "My Label Tab");
This will add a single tab to the tab widget, which contains myLabel.
I'm having a play around with Qt mainly looking to rewrite an old java app for symbian and I have got my self a bit confused.
I should first of all explain that C++ is not my kung-fu, and that may be the cause of the problem.
What I am trying to do is add a simple QPushButton to a Vertical Layout in a main window which has been built in qt designer at run time.
My example code is something like this...
QPushButton button = new QPushButton();
QString text("Testing Buttons");
button.setText(text);
//How do we add children to this widget??
ui->myLayout->addWidget(button);
The errors I am getting are as follows...
/home/graham/myFirstApp/mainwindow.cpp:22:
error: conversion from ‘QPushButton*’
to non-scalar type ‘QPushButton’
requested
/home/graham/myFirstApp/mainwindow.cpp:27:
error: no matching function for call
to
‘QVBoxLayout::addWidget(QPushButton&)’
/home/graham/myFirstApp/../qtsdk-2010.05/qt/include/QtGui/qboxlayout.h:85: candidates are: void
QBoxLayout::addWidget(QWidget*, int,
Qt::Alignment)
Now I know the first error has something to do with pointers but I don't know what, if anyone is able to clear up my confusion and provide example code that would be great.
Regards
Graham.
This is a merely C++ problem, you need to use asterisk to declare the button as pointer when you use new-operator.
QPushButton* button = new QPushButton();
button->setText(text);
ui->myLayout->addWidget(button);
QPushButton button = new QPushButton();
A pointer to QPushButton is not a QPushButton. That's what your compiler's bitching about and that's your problem.