Here is a pruned version of a problem I have using QT/linux. The program runs, but the size of the displayed widget is wrong (the contents, frame + labels, does not fit).
I understood that the size of a windows should be computed fron its contents (children). Why is that not happening properly here?
So the first question is, of course why this is happening.
The real program actually updates the contents of the widget at run-time. I have tried to simulate that behavior by the insertion of the main_window->show() (commented //SHOW1). If this first show() call is made, then the second show() does not show the new contents the widget. I have tried with update without success...
#include <QApplication>
#include <QtCore>
#include <QMainWindow>
#include <QTabWidget>
#include <QWidget>
#include <QGroupBox>
#include <QVBoxLayout>
#include <QLabel>
#include <stdlib.h>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QMainWindow* main_window = new(QMainWindow);
main_window->setObjectName("main_window");
main_window->resize(800, 600);
main_window->setWindowTitle("Hello");
QTabWidget* node_tab_widget = new QTabWidget(main_window);
// node_tab_widget->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
// node_tab_widget->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
node_tab_widget->setObjectName(QString::fromUtf8("tab_widget"));
node_tab_widget->resize(500, 400);
QWidget* w= new QWidget(node_tab_widget);
node_tab_widget->addTab(w, "TAB");
//main_window->show(); //SHOW1
QGroupBox* group_widget = new QGroupBox("GROUPNAME", w);
QVBoxLayout* group_layout = new QVBoxLayout;
group_widget->setLayout(group_layout);
group_layout->addWidget((QLabel*)new QLabel(">>>>>>>>>>>>>>>>>>>>>>>>>here1"));
group_layout->addWidget((QLabel*)new QLabel("here2"));
// group_widget->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
main_window->update();
main_window->show();
return app.exec();
}
I don't really understand what is the result you expect, can be something like what you get from this code:
#include <QApplication>
#include <QtCore>
#include <QMainWindow>
#include <QTabWidget>
#include <QWidget>
#include <QGroupBox>
#include <QVBoxLayout>
#include <QLabel>
#include <stdlib.h>
int main(int argc, char *argv[]) {
QApplication app(argc, argv);
QMainWindow* main_window = new(QMainWindow);
main_window->setObjectName("main_window");
main_window->resize(800, 600);
main_window->setWindowTitle("Hello");
QTabWidget* node_tab_widget = new QTabWidget();
node_tab_widget->setObjectName(QString::fromUtf8("tab_widget"));
node_tab_widget->resize(500, 400);
QWidget* w= new QWidget();
node_tab_widget->addTab(w, "TAB");
QGroupBox* group_widget = new QGroupBox("GROUPNAME", w);
QVBoxLayout* group_layout = new QVBoxLayout;
group_widget->setLayout(group_layout);
group_layout->addWidget((QLabel*)new QLabel(">>>>>>>>>>>>>>>>>>>>>>>>>here1"));
group_layout->addWidget((QLabel*)new QLabel("here2"));
QVBoxLayout* gl = new QVBoxLayout;
gl->addWidget(group_widget);
main_window->setCentralWidget(node_tab_widget);
main_window->show();
return app.exec();
}
which add the QTabWidget node_tab_widget as central widget, with a tab TAB.
The tab contain the QGroupBox GROUPNAME with the two labels (vertical aligned)
Related
I am trying to add a distance sensor to a kuka robot in webots software KUKA robot that has no field called children but I added the distance sensor in bodyslot field now the sensor is reading nan all the time
#include <webots/keyboard.h>
#include <webots/robot.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <webots/distance_sensor.h>
#define TIME_STEP 32
int main(int argc, char **argv) {
wb_robot_init();
//////////////////////////////
WbDeviceTag ps[1];
char ps_names[1][3] = {"DS"};
ps[0] = wb_robot_get_device(ps_names[0]);
wb_distance_sensor_enable(ps[0], TIME_STEP);
////////////////////////////////
// read sensors outputs
double ps_values;
ps_values = wb_distance_sensor_get_value(ps[0]);
//////////////////////////////////////////////////////////
while (true) {
step();
printf ("\n %f \n", ps_values);
//while (ps_values > 80){
base_forwards_increment();
//}
// base_backwards_increment();
}
wb_robot_cleanup();
return 0;
}
enter image description here
To find a way to add a distance sensor to kuka robot
I am using embedded system and I'm testing transparent QWS server where is my Qt4.7.3.
I faced the afterimage in the QDialog when moving cursor in test program which as the QWS client, but it didn't happen in the QMainWindow which in QWS server program.
Can anyone help me to fix the issue?
There is the issue
Here is test program source code.
#include "mainwindow.h"
#include <QApplication>
#include<QWSServer>
#include <QDialog>
#include <fcntl.h>
#include <stdio.h>
#include <sys/ioctl.h>
#include <linux/fb.h>
#include "qscreenlinuxfb_qws.h"
#include "qscreendriverfactory_qws.h"
#include <errno.h>
extern "C" {
extern int Test();
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QDialog w;
QWSServer::setBackground(QColor(0,0,0,0));
QWSServer::setCursorVisible(false);
w.setStyleSheet("background-color:transparent;");
w.show();
return a.exec();
}
OK I found the issue. In QT source code.
src\gui\embedded\qscreen_qws.cpp
if (!blendSize.isNull()) {
*blendbuffer = new QImage(blendSize, d_ptr->preferredImageFormat());
}
to
if (!blendSize.isNull()) {
*blendbuffer = new QImage(blendSize, d_ptr->preferredImageFormat());
QPixmap temp = QPixmap(blendSize);
temp.fill(Qt::transparent);
**blendbuffer = temp.toImage();
}
Client server must pass to the Server process a filename and the Server process must return the number of lines in the file. My problem is that the received variable only contains 6 characters of the filename and it ends up by throwing segmentation fault dump core error. Do you know why this happens? This is my code:
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <string.h>
int main(){
int fd1,fd2;
const char *fifo1="./fifo1Channel";
const char *fifo2="./fifo2Channel";
mkfifo(fifo1,0666);
mkfifo(fifo2,0666);
char filename[30];
printf("Give me a filename:\n");
fgets(filename,30,stdin);
strtok(filename,"\n");
int pid=fork();
if(pid>0){
char received[30], ch;
FILE *fp;
fd1=open(fifo1, O_RDONLY);
read(fd1,received,strlen(received));
close(fd1);
printf("From server process:%s\n",received);
fp=fopen(received,"r");
int nrOfLines=0;
for(ch=getc(fp);ch!=EOF;ch=getc(fp))
if(ch=='\n')
nrOfLines++;
fd2=open(fifo2, O_WRONLY);
write(fd2,&nrOfLines,sizeof(nrOfLines));
close(fd2);
return 0;
}
if(pid==0){
int receivedNumber;
fd1=open(fifo1,O_WRONLY);
write(fd1,filename,strlen(filename));
close(fd1);
fd2=open(fifo2,O_RDONLY);
read(fd2,&receivedNumber,sizeof(receivedNumber));
close(fd2);
printf("From client process: %d\n",receivedNumber);
return 0;
}
return 0;
}
I think the problem was in server process. I replaced strlen(received) with 30, the maximum number of characters of filename, in function read and it works now!
fatal error: 'thread' file not found
this is main.cpp.
#include <QApplication>
#include <QMainWindow>
#include <thread>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QMainWindow w;
w.show();
return a.exec();
}
this is pro file.
QT += core gui opengl
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = empty
TEMPLATE = app
DEFINES += CC_TARGET_QT5
CONFIG += c++11
SOURCES += main.cpp
a strange question. why ?
Based on this bug i'm trying to write an entry in /var/run/utmp to simulate the problem http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=528060 , i tryed with this code taken from manpages, but didn't work
#include <string.h>
#include <stdlib.h>
#include <pwd.h>
#include <unistd.h>
#include <utmp.h>
int
main(int argc, char *argv[])
{
struct utmp entry;
system("echo before adding entry:;who");
entry.ut_type = USER_PROCESS;
entry.ut_pid = getpid();
strcpy(entry.ut_line, ttyname(STDIN_FILENO) + strlen("/dev/"));
/* only correct for ptys named /dev/tty[pqr][0-9a-z] */
strcpy(entry.ut_id, ttyname(STDIN_FILENO) + strlen("/dev/tty"));
time(&entry.ut_time);
strcpy(entry.ut_user, getpwuid(getuid())->pw_name);
memset(entry.ut_host, 0, UT_HOSTSIZE);
entry.ut_addr = 0;
setutent();
pututline(&entry);
system("echo after adding entry:;who");
exit(EXIT_SUCCESS);
}
I solved my problem with this code
#include <string.h>
#include <stdlib.h>
#include <pwd.h>
#include <unistd.h>
#include <utmp.h>
int
main(int argc, char *argv[])
{
struct utmp entry;
system("echo before adding entry:;who");
entry.ut_type = USER_PROCESS;
entry.ut_pid = getpid();
strcpy(entry.ut_line, ttyname(STDIN_FILENO) + strlen("/dev/"));
/* only correct for ptys named /dev/tty[pqr][0-9a-z] */
strcpy(entry.ut_id, ttyname(STDIN_FILENO) + strlen("/dev/tty"));
time(&entry.ut_time);
//strcpy(entry.ut_user, getpwuid(getuid())->pw_name);
strcpy(entry.ut_user, "pippo");
memset(entry.ut_host, 0, UT_HOSTSIZE);
entry.ut_addr = 0;
setutent();
pututline(&entry);
system("echo after adding entry:;who");
exit(EXIT_SUCCESS);
}