I've installed VTK 8.2.0 with CMake for use with QT but when trying to run some VTK examples I have some issues shown below:
Note: The colour banding issues in the image is from the gif compression and is not part of the issue
#include <vtkSmartPointer.h>
#include <vtkActor.h>
#include <vtkCubeSource.h>
#include <vtkPolyData.h>
#include <vtkPolyDataMapper.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>
int main(int, char *[])
{
// Create a cube.
vtkSmartPointer<vtkCubeSource> cubeSource =
vtkSmartPointer<vtkCubeSource>::New();
// Create a mapper and actor.
vtkSmartPointer<vtkPolyDataMapper> mapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(cubeSource->GetOutputPort());
vtkSmartPointer<vtkActor> actor =
vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);
// Create a renderer, render window, and interactor
vtkSmartPointer<vtkRenderer> renderer =
vtkSmartPointer<vtkRenderer>::New();
vtkSmartPointer<vtkRenderWindow> renderWindow =
vtkSmartPointer<vtkRenderWindow>::New();
renderWindow->AddRenderer(renderer);
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
renderWindowInteractor->SetRenderWindow(renderWindow);
// Add the actors to the scene
renderer->AddActor(actor);
renderer->SetBackground(.3, .2, .1);
// Render and interact
renderWindow->Render();
renderWindowInteractor->Start();
return EXIT_SUCCESS;
}
https://vtk.org/Wiki/VTK/Examples/Cxx/GeometricObjects/Cube
For all of the examples, it appears that the previous frame is not being cleared and the background is not being shown over it.
I don't appear to get any error messages when compiling or running the program. Might it be a driver issue?
Any help would be much appreciated!
Related
i want to add a music in my game for a school project in qt but i saw that we have to use setMedia but he don't recognize it in the QMediaPLayer class and video about it are from so 2015 i think it change and i put a setSource but nos sound is coming from my game. I tried this but i don't have any ideas to make it work. Please help me.
#include <QMediaPlayer>
QMediaPlayer * player = new QMediaPlayer();
player->setSource(QUrl::fromLocalFile("C:/Users/Lea_CHABBAL/OneDrive/Bureau"));
player->play();
So that an audio file can be output, you must also set the output of your media player.
It is also important to make an entry in your project file:
qmake :
QT += core gui multimedia (add multimedia)
The code could then look like this:
#include <QMediaPlayer>
#include <QAudioOutput>
........
// if you want to use it as SLOT, it will be make sense to
// declare the mediaplayer and output in a header file
QMediaPlayer *player = new QMediaPlayer;
QAudioOutput *output = new QAudioOutput;
player->setAudioOutput(output);
player->setSource(QUrl("path"));
output->setVolume(0.5); // <--- floating numbers. from 0 - 1
player->play();
........
Try this (and don't forget the filename.wav at the end of the path)
musicPlayer = new QMediaPlayer(this);
musicPlayer->setVolume(30);
musicPlayer->setSource(QUrl::fromLocalFile("C:/Users/Lea_CHABBAL/OneDrive/Bureau/daftpunk_compil.wav"));
if(musicPlayer->error() == QMediaPlayer::NoError)
musicPlayer->play();
else
qDebug()<<musicPlayer->errorString();
Our company is in need to capture the rendering of a Qt3d scene. For this I created a small example application, that illustrates the usage of our capturing.
On the left-hand side you will find the 3D scene and on the right-hand side there is a QLabel with a QPixmap showing the captured screen.
Now, for some reason I really don't understand the captured screenshot really looks different compared to the 3D scene on the left hand side. Even more confusing the saved PNG images looks different compared to QLabel on the right hand side, but actually I'm more interested in the PNG for my use case.
It saves me the following PNG file:
I already tried to insert the QRenderCapture in different place of the frame graph, but none of the places gave reasonable results.
This is my frameGraph->dumpObjectTree output:
Qt3DExtras::QForwardRenderer::
Qt3DRender::QRenderSurfaceSelector::
Qt3DRender::QViewport::
Qt3DRender::QCameraSelector::
Qt3DRender::QClearBuffers::
Qt3DRender::QFrustumCulling::
Qt3DRender::QCamera::
Qt3DRender::QCameraLens::
Qt3DCore::QTransform::
Qt3DRender::QRenderCapture:: // Insertion of QRenderCapture
Qt3DRender::QFilterKey::
It seems, that I capture the 3d scene somewhere during the rendering, so that there might be some timing issues. (Maybe the usage of QEventLoop is not admissible in this use case, but I really don't know why.)
The documentation of QRenderCapture implies, that QRenderCapture should be the last leafnode of the frame graph, but this is what I did.
From QRenderCapture documentation:
The QRenderCapture is used to capture rendering into an image at any render stage. Capturing must be initiated by the user and one
image is returned per capture request. User can issue multiple render
capture requests simultaneously, but only one request is served per
QRenderCapture instance per frame.
And also:
Used to request render capture. Only one render capture result is
produced per requestCapture call even if the frame graph has multiple
leaf nodes. The function returns a QRenderCaptureReply object, which
receives the captured image when it is done. The user is responsible
for deallocating the returned object.
Can someone here help me out?
#include <QApplication>
#include <QVBoxLayout>
#include <QLabel>
#include <QPushButton>
#include <Qt3DRender/QRenderCapture>
#include <Qt3DRender/QCamera>
#include <Qt3DExtras/QSphereMesh>
#include <Qt3DExtras/QDiffuseSpecularMaterial>
#include <Qt3DExtras/QForwardRenderer>
#include <Qt3DExtras/Qt3DWindow>
Qt3DCore::QEntity* transparentSphereEntity() {
auto entity = new Qt3DCore::QEntity;
auto meshMaterial = new Qt3DExtras::QDiffuseSpecularMaterial();
meshMaterial->setAlphaBlendingEnabled(true);
meshMaterial->setDiffuse(QColor(255, 0, 0, 50));
auto mesh = new Qt3DExtras::QSphereMesh();
mesh->setRadius(1.0);
entity->addComponent(mesh);
entity->addComponent(meshMaterial);
return entity;
}
int main(int argc, char* argv[])
{
QApplication a(argc, argv);
auto frame = new QFrame;
auto view = new Qt3DExtras::Qt3DWindow();
auto camera = new Qt3DRender::QCamera;
camera->lens()->setPerspectiveProjection(45.0f, 1., 0.1f, 10000.0f);
camera->setPosition(QVector3D(0, 0, 10));
camera->setUpVector(QVector3D(0, 1, 0));
camera->setViewCenter(QVector3D(0, 0, 0));
view->defaultFrameGraph()->setCamera(camera);
auto frameGraph = view->defaultFrameGraph();
frameGraph->dumpObjectTree();
auto camSelector = frameGraph->findChild<Qt3DRender::QCamera*>();
auto renderCapture = new Qt3DRender::QRenderCapture(camSelector);
frameGraph->dumpObjectTree();
auto rootEntity = new Qt3DCore::QEntity();
view->setRootEntity(rootEntity);
auto sphere = transparentSphereEntity();
sphere->setParent(rootEntity);
auto btnScreenshot = new QPushButton("Take Screenshot");
auto labelPixmap = new QLabel;
frame->setLayout(new QHBoxLayout);
frame->layout()->addWidget(QWidget::createWindowContainer(view));
frame->layout()->addWidget(btnScreenshot);
frame->layout()->addWidget(labelPixmap);
frame->setMinimumSize(1000, 1000 / 3);
frame->show();
QObject::connect(btnScreenshot, &QPushButton::clicked, [&]() {
QEventLoop loop;
auto reply = renderCapture->requestCapture();
QObject::connect(reply, &Qt3DRender::QRenderCaptureReply::completed, [&] {
reply->image().save("./data/test.png");
labelPixmap->setPixmap(QPixmap::fromImage(reply->image()));
loop.quit();
});
loop.exec();
});
return a.exec();
}
I have a problem using smart pointers with Qt. I can´t figure out what is the reason for that strange behaviour.
Simple Setup:
I created a new Qt Widgets Application and dragged a QGraphicsView into the main window and only added the following Code to paint a circle:
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "QGraphicsScene"
#include "QGraphicsEllipseItem"
#include "boost/shared_ptr.hpp"
#include "QSharedPointer"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QGraphicsScene* scene = new QGraphicsScene(ui->graphicsView);
ui->graphicsView->setScene(scene);
/* 1. raw pointer */
QGraphicsEllipseItem* ell = new QGraphicsEllipseItem(100,100,50,50);
scene->addItem(ell);
/* 2. boost shared pointer
boost::shared_ptr<QGraphicsEllipseItem> eSP(new QGraphicsEllipseItem(100,100,50,50));
scene->addItem(eSP.get());*/
/* 3. Qt shared pointer
QSharedPointer<QGraphicsEllipseItem> eSP(new QGraphicsEllipseItem(100,100,50,50));
scene->addItem(eSP.data());*/
/* 4a. raw pointer as init parameter for shared pointer
QGraphicsEllipseItem* ell = new QGraphicsEllipseItem(100,100,50,50);
boost::shared_ptr<QGraphicsEllipseItem> eSP(ell);
scene->addItem(eSP.get()); // using shared pointer */
/* 4b. raw pointer as init parameter for shared pointer
QGraphicsEllipseItem* ell = new QGraphicsEllipseItem(100,100,50,50);
boost::shared_ptr<QGraphicsEllipseItem> eSP(ell);
scene->addItem(ell); // using raw pointer */
}
MainWindow::~MainWindow()
{
delete ui;
}
As you can see I tried some variants. The first one ist the only one that works. It paints a circle in the center of the QGraphicsView. But for my project I need a smart pointer implementation. But all the smart pointer implementations do not paint the circle.
Am I making any mistake???
Especially 4b confuses me most. The only difference to 1 is that I am putting the raw pointer additionally into a shared pointer and that won´t work
Please help me!
My environment:
- Linux Mint 17.1
- qt-sdk 2ubuntu3
- boost 1.54.0.1
I have a project "Cybaware_ver1" on QtCreator based on QWidget and everything was working fine. I have a header file with a class containing public and private variables and functions. However, since one day whenever I try to declare a new variable in the header file, even an "int" variable, and run the project, I get
The program has unexpectedly finished.
/home/devdeep/Cybaware_ver1-build-Desktop_Qt_5_0_0_GCC_64bit_SDK-Debug/Cybaware_ver1 exited with code 0
Previously I could add variables in the header file without any problem. Currently, I am able to add new functions, modify UI etc. Just I am unable to add variables to the header file. I have found a temporary solution of declaring these variables as static in the cpp file. However, I would like to find a solution to this.
I have tried re-installing Qt but the problem still persists. I am running it on Ubuntu Linux.
Please let me know if there is a way to fix this. Also, I am not sure what other information I can provide. So please let me know about that.
UPDATE: OK. I used the debugger at it says that the error is a segmentation fault.
It points to the following section of qdebug.h and to the line marked by qt_message_output.
public:
inline QDebug(QIODevice *device) : stream(new Stream(device)) {}
inline QDebug(QString *string) : stream(new Stream(string)) {}
inline QDebug(QtMsgType t) : stream(new Stream(t)) {}
inline QDebug(const QDebug &o):stream(o.stream) { ++stream->ref; }
inline QDebug &operator=(const QDebug &other);
inline ~QDebug() {
if (!--stream->ref) {
if(stream->message_output) {
QT_TRY {
qt_message_output(stream->type,
stream->context,
stream->buffer);
} QT_CATCH(std::bad_alloc&) { /* We're out of memory - give up. */ }
}
delete stream;
}
}
I guess it is a out of memory error. Possible, closing other programs might help?
UPDATE2: Calling "run qmake" did not help. Here is my header file:
#ifndef MAINVIEW_H
#define MAINVIEW_H
#include <QWidget>
#include <QGraphicsScene>
#include <QGraphicsRectItem>
#include <QGraphicsLineItem>
#include <QGraphicsEllipseItem>
#include <QGraphicsSimpleTextItem>
#include <list>
#include <QMouseEvent>
#include <QEvent>
#include <QString>
#include <boost/thread.hpp>
#include <qcustomplot.h>
#include <QTimer>
namespace Ui {
class MainView;
}
class MainView : public QWidget
{
Q_OBJECT
public:
int num_missions;
int num_services;
int timer;
int* num_servpermission;
int missionstartx;
//boost::thread pt;
QGraphicsScene mynewscene;
QGraphicsRectItem* myrect;
QGraphicsRectItem** missionline;
QGraphicsLineItem** missionplayline;
QGraphicsRectItem** playrect;
std::list<QGraphicsLineItem**> missionticks;
std::list<QGraphicsEllipseItem**> missionservices;
std::list<QGraphicsSimpleTextItem**> missionservicesno;
std::list<QGraphicsLineItem**>::iterator ti;
std::list<QGraphicsSimpleTextItem**>::iterator ssi;
//std::list<QGraphicsEllipseItem**>::iterator si;
int* missionlength;
int** missionplayxy;
int* missiontickscount;
int* missioniteration;
int missionselected;
int missiontickselected;
int missiontickoffset;
bool isrepeated;
int temp;
QCustomPlot** customPlot;
QTimer dataTimer;
explicit MainView(QWidget *parent = 0);
void playthread();
bool eventFilter(QObject*, QEvent*);
void testfunc();
void clearview();
void test1();
~MainView();
private slots:
void on_startButton_clicked();
void realtimeDataPlot();
void on_pushButton_clicked();
private:
Ui::MainView *ui;
};
#endif // MAINVIEW_H
The program crashes on adding any variable. For example, I added the variable int temp just now and it would crash. Adding anything new makes it crash such as uncommenting the declaration std::list::iterator si;. I take it out and everything works fine.
UPDATE3: My external header file qcustomplot.h is located in the same directory. I am also using boost but that I set up using apt-get. Here is the stack trace:
0 MainView::playthread mainview.cpp 530 0x418fa1
1 boost::_mfi::mf0::operator() mem_fn_template.hpp 49 0x424690
2 boost::_bi::list1 >::operator(), boost::_bi::list0> bind.hpp 253 0x424600
3 boost::_bi::bind_t, boost::_bi::list1 > >::operator() bind_template.hpp 20 0x4245af
4 boost::detail::thread_data, boost::_bi::list1 > > >::run thread.hpp 61 0x42431c
5 thread_proxy /usr/lib/libboost_thread.so.1.46.1 0x7ffff7bcfba9
6 start_thread /lib/x86_64-linux-gnu/libpthread.so.0 0x7ffff6557efc
7 clone /lib/x86_64-linux-gnu/libc.so.6 0x7ffff5af159d
8 ??
The 0th pt in the above trace points to
ui->missionview->invalidateScene()
Here the graphics view gets updated from a function playthread binded to a boost thread. But I am not sure why this would be a problem on adding a variable in the header file as I am not using the variable anywhere in the cpp file.
Go into the project folder and delete the *.pro.user file. Next time you open the project you'll just need to reconfigure it (i.e. choose the appropriate build kit).
I know this is an old thread, but I ran into the same problem myself. Every time I tried to add a variable to my header file it was causing a heap corruption error. I wasn't allocating memory on the heap, or even declaring pointer variables for that matter. It was very frustrating because I didn't know what it was at first. I finally narrowed it down to adding variables to my header file causing the crash. Based on doomguy's experience I knew that it was something persistent in the build folder because he said reinstalling Qt didn't work. I'm glad I read that because I would have been pissed if I reinstalled this behemoth and it still didn't work. Based on prior experience corruption in the .user file can cause issues, and deleting it kinda gives you a clean slate. Moral of the story: If you're getting unusual behavior that seems to point to a problem in the IDE try deleting the .user file before trying more extreme measures.
Not sure if the problem is cause by this, but if the header contains a QObject derived class you should run qmake and after that build your application.
LE: also if this isn't the case, i suggest that you show us a little more code (your code, not Qt code)
Is there any way to get lists of all timezones IST, ET etc.
I have to use them in my application.
The ICU Library is portable and can be used in a Qt application. (It has a C/C++ API.) Among its many other features, is has a TimeZone class that can enumerate the time zones known by the system.
TimeZone Class
It might be overkill if all you need is a simple list, but if you expect to use these time zones and interact with other metadata (locales, etc.), this would be a good solution.
There is a another example using the new QTimeZone class in qt5.2 described here.
They create a custom Widget which lists all known timezones plus their special settings like daylight saving times and such.
The basic code posted there is:
#include <QDebug>
#include <QByteArray>
#include <QDateTime>
#include <QList>
#include <QTimeZone>
#include "widget.h"
#include "ui_widget.h"
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
// Fill in combo box.
QList<QByteArray> ids = QTimeZone::availableTimeZoneIds();
foreach (QByteArray id, ids) {
ui->timeZoneComboBox->addItem(id);
}
// Connect combo box to slot to update fields.
connect(ui->timeZoneComboBox, SIGNAL(currentIndexChanged(int)),
SLOT(UpdateFields()));
// Update fields for initial value.
UpdateFields();
}
void Widget::UpdateFields() {
QByteArray id = ui->timeZoneComboBox->currentText().toLatin1();
QTimeZone zone = QTimeZone(id);
// Fill in fields for current time zone.
if (zone.isValid()) {
ui->descriptionLabel->setText(tr("<b>Description:</b> ") + id);
ui->countryLabel->setText(tr("<b>Country:</b> ") +
QLocale::countryToString(zone.country()));
ui->hasDaylightTimeCheckBox->setChecked(zone.hasDaylightTime());
ui->isDaylightTimeCheckBox->setChecked(
zone.isDaylightTime(QDateTime::currentDateTime()));
ui->hasTransitionsCheckBox->setChecked(zone.hasTransitions());
QDateTime zoneTime = QDateTime(
QDate::currentDate(), QTime::currentTime(), zone).toLocalTime();
ui->dateEdit->setDate(zoneTime.date());
ui->timeEdit->setTime(zoneTime.time());
QTimeZone::OffsetData offset = zone.nextTransition(
QDateTime::currentDateTime());
if (offset.atUtc != QDateTime()) {
ui->nextTransitionLabel->setEnabled(true);
ui->nextTransitionLabel->setText(
tr("<b>Next transition:</b> %1").arg(offset.atUtc.toString()));
} else {
ui->nextTransitionLabel->setEnabled(false);
ui->nextTransitionLabel->setText(
tr("<b>Next transition:</b> none"));
}
}
}
Do you need to somehow find it during runtime, or for your source code? If the second case, you can use this list.
Yes try this example
http://www.developer.nokia.com/Community/Wiki/How_to_get_list_of_Time_Zones_in_Qt_Maemo_application