Can't write to Binary File C++ - c++98

So , I am currently Doing an project where i need to create a file to store contacts , read them , modify .....
Everything was working perfectly but after a few days once i opened and ran the file again it screwed up everything it just wont write the file
once i write the file , all i get is 100 blank spaces and i know why 100 becuase each data member in my class is 20 and therefore i have 5 so 5x20=100
But i dont knoq why this is not writing NOTE: This was working perfectly before
,also i tried many things but it dosnt want to write....
code:
void contacts::createnew()
{
ofstream fout;
fout.open("contacts.c",ios::binary||ios::out);
input();
display();
fout.write( (char*) &c, sizeof(c));
fout.close();
view();
cout<<fout.good()<<fout.bad()<<fout.fail();
}
class contacts
{
private:
char name[20];
addline_1[20];
addline_2[20];
email_id[20];
char ph_no[10];
mob_no[10];
public:
void init();
//get contacts details by input
void input()
{
// Implementation here...
}
void display()
{
// Implementation here...
}
void createnew();
void view();
}

Related

Qpid Proton: sending messages to two destinations

Currently, I am able to send messages to a single queue "devQueue". When the message arrives to a "devQueue", it needs to be sent to the "localQueue" as well. I am finding this implementation challenging. I tried to call a different class "local_send" from "class1" class so I can connect to the other destination which is "localQueue" (as shown in the code below) but with no luck. Is there any proton function that would be useful or can I use the reference variable from on_connection_open() within "class1" class inside v_message() function? Any help or idea in this direction would be greatly appreciated.
Currently the code is not getting into "local_send" class and hence the messages are not being sent to "localQueue".
class class1 : public proton::messaging_handler {
std::string url;
std::string devQueue;
std::string localQueue;
std::vector<proton::message> msgVector;
local_send snd;
std::vector<proton::message> msgV;
public:
class1(const std::string& u, const std::string& devQueue, const std::string& localQueue) :
url(u), devQueue(devQueue), localQueue(localQueue), snd(msgVector, localQueue) {}
void on_container_start(proton::container& c) override {
c.connect(url);
}
void on_connection_open(proton::connection& c) override {
c.open_receiver(devQueue);
}
void on_message(proton::delivery &d, proton::message &msg) override {
msgV.push_back(msg);
// Here, the messages are checked if they have a valid format or not and v_message() is called
}
void v_message(const pack& msg){
this->msgVector.push_back(msg);
//I need to send the message to localQueue and hence we are running another class from here (but that is not working :( )
local_send snd(msgVector, localQueue);
proton::container(snd).run();
}
void on_sendable(proton::sender &s) override {
for(auto msg: msgVector){
s.send(msg);
}
}
};
// Do I even need this class to send message to another destination?
class local_send : public proton::messaging_handler {
std::string localQueue;
std::vector<proton::message> msgVector;
public:
local_send(std::vector<proton::message> msgVector, const std::string& localQueue) :
msgVector(msgVector), localQueue(localQueue) {}
void on_connection_open(proton::connection& c) override {
c.open_receiver(localQueue);
}
void on_sendable(proton::sender &s) override {
for(auto msg: msgVector){
s.send(msg);
}
}
};
You need to call open_sender to create a channel for sending messages. You can do this all in one handler. Pseudo code:
proton::sender snd;
on_connection_open(conn) {
conn.open_receiver("queue1");
snd = conn.open_sender("queue2");
}
on_message(dlv, msg) {
// Relay message from queue1 to queue2
snd.send(msg);
}
This snippet doesn't use on_sendable. The send is buffered in the library. If you prefer, you can use a vector of messages as you've done in your code and use on_sendable (in the same handler) to send when there's credit.

API for Windows 10 virtual desktops [duplicate]

I love that Windows 10 now has support for virtual desktops built in, but I have some features that I'd like to add/modify (e.g., force a window to appear on all desktops, launch the task view with a hotkey, have per-monitor desktops, etc.)
I have searched for applications and developer references to help me customize my desktops, but I have had no luck.
Where should I start? I am looking for Windows API functions (ideally, that are callable from a C# application) that will give me programmatic access to manipulate virtual desktops and the windows therein.
The Windows SDK Support Team Blog posted a C# demo to switch Desktops via IVirtualDesktopManager:
[ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("a5cd92ff-29be-454c-8d04-d82879fb3f1b")]
[System.Security.SuppressUnmanagedCodeSecurity]
public interface IVirtualDesktopManager
{
[PreserveSig]
int IsWindowOnCurrentVirtualDesktop(
[In] IntPtr TopLevelWindow,
[Out] out int OnCurrentDesktop
);
[PreserveSig]
int GetWindowDesktopId(
[In] IntPtr TopLevelWindow,
[Out] out Guid CurrentDesktop
);
[PreserveSig]
int MoveWindowToDesktop(
[In] IntPtr TopLevelWindow,
[MarshalAs(UnmanagedType.LPStruct)]
[In]Guid CurrentDesktop
);
}
[ComImport, Guid("aa509086-5ca9-4c25-8f95-589d3c07b48a")]
public class CVirtualDesktopManager
{
}
public class VirtualDesktopManager
{
public VirtualDesktopManager()
{
cmanager = new CVirtualDesktopManager();
manager = (IVirtualDesktopManager)cmanager;
}
~VirtualDesktopManager()
{
manager = null;
cmanager = null;
}
private CVirtualDesktopManager cmanager = null;
private IVirtualDesktopManager manager;
public bool IsWindowOnCurrentVirtualDesktop(IntPtr TopLevelWindow)
{
int result;
int hr;
if ((hr = manager.IsWindowOnCurrentVirtualDesktop(TopLevelWindow, out result)) != 0)
{
Marshal.ThrowExceptionForHR(hr);
}
return result != 0;
}
public Guid GetWindowDesktopId(IntPtr TopLevelWindow)
{
Guid result;
int hr;
if ((hr = manager.GetWindowDesktopId(TopLevelWindow, out result)) != 0)
{
Marshal.ThrowExceptionForHR(hr);
}
return result;
}
public void MoveWindowToDesktop(IntPtr TopLevelWindow, Guid CurrentDesktop)
{
int hr;
if ((hr = manager.MoveWindowToDesktop(TopLevelWindow, CurrentDesktop)) != 0)
{
Marshal.ThrowExceptionForHR(hr);
}
}
}
it includes the API to detect on which desktop the Window is shown and it can switch and move a Windows the a Desktop.
Programmatic access to the virtual desktop feature is very limited, as Microsoft has only exposed the IVirtualDesktopManager COM interface. It does provide two key functions:
IVirtualDesktopManager::GetWindowDesktopId allows you to retrieve the ID of a virtual desktop, based on a window that is already assigned to that desktop.
IVirtualDesktopManager::MoveWindowToDesktop allows you to move a window to a specific virtual desktop.
Unfortunately, this is not nearly enough to accomplish anything useful. I've written some C# code based on the reverse-engineering work done by NickoTin. I can't read much of the Russian in his blog post, but his C++ code was pretty accurate.
I do need to emphasize that this code is not something you want to commit to in a product. Microsoft always feels free to change undocumented APIs whenever they feel like it. And there is a runtime risk as well: this code does not necessarily interact well when the user is tinkering with the virtual desktops. Always keep in mind that a virtual desktop can appear and disappear at any time, completely out of sync with your code.
To use the code, create a new C# class library project. I'll first post ComInterop.cs, it contains the COM interface declarations that match NickoTin's C++ declarations:
using System;
using System.Runtime.InteropServices;
namespace Windows10Interop {
internal static class Guids {
public static readonly Guid CLSID_ImmersiveShell =
new Guid(0xC2F03A33, 0x21F5, 0x47FA, 0xB4, 0xBB, 0x15, 0x63, 0x62, 0xA2, 0xF2, 0x39);
public static readonly Guid CLSID_VirtualDesktopManagerInternal =
new Guid(0xC5E0CDCA, 0x7B6E, 0x41B2, 0x9F, 0xC4, 0xD9, 0x39, 0x75, 0xCC, 0x46, 0x7B);
public static readonly Guid CLSID_VirtualDesktopManager =
new Guid("AA509086-5CA9-4C25-8F95-589D3C07B48A");
public static readonly Guid IID_IVirtualDesktopManagerInternal =
new Guid("AF8DA486-95BB-4460-B3B7-6E7A6B2962B5");
public static readonly Guid IID_IVirtualDesktop =
new Guid("FF72FFDD-BE7E-43FC-9C03-AD81681E88E4");
}
[ComImport]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
[Guid("FF72FFDD-BE7E-43FC-9C03-AD81681E88E4")]
internal interface IVirtualDesktop {
void notimpl1(); // void IsViewVisible(IApplicationView view, out int visible);
Guid GetId();
}
[ComImport]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
[Guid("AF8DA486-95BB-4460-B3B7-6E7A6B2962B5")]
internal interface IVirtualDesktopManagerInternal {
int GetCount();
void notimpl1(); // void MoveViewToDesktop(IApplicationView view, IVirtualDesktop desktop);
void notimpl2(); // void CanViewMoveDesktops(IApplicationView view, out int itcan);
IVirtualDesktop GetCurrentDesktop();
void GetDesktops(out IObjectArray desktops);
[PreserveSig]
int GetAdjacentDesktop(IVirtualDesktop from, int direction, out IVirtualDesktop desktop);
void SwitchDesktop(IVirtualDesktop desktop);
IVirtualDesktop CreateDesktop();
void RemoveDesktop(IVirtualDesktop desktop, IVirtualDesktop fallback);
IVirtualDesktop FindDesktop(ref Guid desktopid);
}
[ComImport]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
[Guid("a5cd92ff-29be-454c-8d04-d82879fb3f1b")]
internal interface IVirtualDesktopManager {
int IsWindowOnCurrentVirtualDesktop(IntPtr topLevelWindow);
Guid GetWindowDesktopId(IntPtr topLevelWindow);
void MoveWindowToDesktop(IntPtr topLevelWindow, ref Guid desktopId);
}
[ComImport]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
[Guid("92CA9DCD-5622-4bba-A805-5E9F541BD8C9")]
internal interface IObjectArray {
void GetCount(out int count);
void GetAt(int index, ref Guid iid, [MarshalAs(UnmanagedType.Interface)]out object obj);
}
[ComImport]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
[Guid("6D5140C1-7436-11CE-8034-00AA006009FA")]
internal interface IServiceProvider10 {
[return: MarshalAs(UnmanagedType.IUnknown)]
object QueryService(ref Guid service, ref Guid riid);
}
}
Next is Desktop.cs. It contains the friendly C# classes that you can use in your code:
using System;
using System.Runtime.InteropServices;
namespace Windows10Interop
{
public class Desktop {
public static int Count {
// Returns the number of desktops
get { return DesktopManager.Manager.GetCount(); }
}
public static Desktop Current {
// Returns current desktop
get { return new Desktop(DesktopManager.Manager.GetCurrentDesktop()); }
}
public static Desktop FromIndex(int index) {
// Create desktop object from index 0..Count-1
return new Desktop(DesktopManager.GetDesktop(index));
}
public static Desktop FromWindow(IntPtr hWnd) {
// Creates desktop object on which window <hWnd> is displayed
Guid id = DesktopManager.WManager.GetWindowDesktopId(hWnd);
return new Desktop(DesktopManager.Manager.FindDesktop(ref id));
}
public static Desktop Create() {
// Create a new desktop
return new Desktop(DesktopManager.Manager.CreateDesktop());
}
public void Remove(Desktop fallback = null) {
// Destroy desktop and switch to <fallback>
var back = fallback == null ? DesktopManager.GetDesktop(0) : fallback.itf;
DesktopManager.Manager.RemoveDesktop(itf, back);
}
public bool IsVisible {
// Returns <true> if this desktop is the current displayed one
get { return object.ReferenceEquals(itf, DesktopManager.Manager.GetCurrentDesktop()); }
}
public void MakeVisible() {
// Make this desktop visible
DesktopManager.Manager.SwitchDesktop(itf);
}
public Desktop Left {
// Returns desktop at the left of this one, null if none
get {
IVirtualDesktop desktop;
int hr = DesktopManager.Manager.GetAdjacentDesktop(itf, 3, out desktop);
if (hr == 0) return new Desktop(desktop);
else return null;
}
}
public Desktop Right {
// Returns desktop at the right of this one, null if none
get {
IVirtualDesktop desktop;
int hr = DesktopManager.Manager.GetAdjacentDesktop(itf, 4, out desktop);
if (hr == 0) return new Desktop(desktop);
else return null;
}
}
public void MoveWindow(IntPtr handle) {
// Move window <handle> to this desktop
DesktopManager.WManager.MoveWindowToDesktop(handle, itf.GetId());
}
public bool HasWindow(IntPtr handle) {
// Returns true if window <handle> is on this desktop
return itf.GetId() == DesktopManager.WManager.GetWindowDesktopId(handle);
}
public override int GetHashCode() {
return itf.GetHashCode();
}
public override bool Equals(object obj) {
var desk = obj as Desktop;
return desk != null && object.ReferenceEquals(this.itf, desk.itf);
}
private IVirtualDesktop itf;
private Desktop(IVirtualDesktop itf) { this.itf = itf; }
}
internal static class DesktopManager {
static DesktopManager() {
var shell = (IServiceProvider10)Activator.CreateInstance(Type.GetTypeFromCLSID(Guids.CLSID_ImmersiveShell));
Manager = (IVirtualDesktopManagerInternal)shell.QueryService(Guids.CLSID_VirtualDesktopManagerInternal, Guids.IID_IVirtualDesktopManagerInternal);
WManager = (IVirtualDesktopManager)Activator.CreateInstance(Type.GetTypeFromCLSID(Guids.CLSID_VirtualDesktopManager));
}
internal static IVirtualDesktop GetDesktop(int index) {
int count = Manager.GetCount();
if (index < 0 || index >= count) throw new ArgumentOutOfRangeException("index");
IObjectArray desktops;
Manager.GetDesktops(out desktops);
object objdesk;
desktops.GetAt(index, Guids.IID_IVirtualDesktop, out objdesk);
Marshal.ReleaseComObject(desktops);
return (IVirtualDesktop)objdesk;
}
internal static IVirtualDesktopManagerInternal Manager;
internal static IVirtualDesktopManager WManager;
}
}
And finally a little test WinForms project that I used to test the code. Just drop 4 buttons on a form and name them buttonLeft/Right/Create/Destroy:
using Windows10Interop;
using System.Diagnostics;
...
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
}
private void buttonRight_Click(object sender, EventArgs e) {
var curr = Desktop.FromWindow(this.Handle);
Debug.Assert(curr.Equals(Desktop.Current));
var right = curr.Right;
if (right == null) right = Desktop.FromIndex(0);
if (right != null) {
right.MoveWindow(this.Handle);
right.MakeVisible();
this.BringToFront();
Debug.Assert(right.IsVisible);
}
}
private void buttonLeft_Click(object sender, EventArgs e) {
var curr = Desktop.FromWindow(this.Handle);
Debug.Assert(curr.Equals(Desktop.Current));
var left = curr.Left;
if (left == null) left = Desktop.FromIndex(Desktop.Count - 1);
if (left != null) {
left.MoveWindow(this.Handle);
left.MakeVisible();
this.BringToFront();
Debug.Assert(left.IsVisible);
}
}
private void buttonCreate_Click(object sender, EventArgs e) {
var desk = Desktop.Create();
desk.MoveWindow(this.Handle);
desk.MakeVisible();
Debug.Assert(desk.IsVisible);
Debug.Assert(desk.Equals(Desktop.Current));
}
private void buttonDestroy_Click(object sender, EventArgs e) {
var curr = Desktop.FromWindow(this.Handle);
var next = curr.Left;
if (next == null) next = curr.Right;
if (next != null && next != curr) {
next.MoveWindow(this.Handle);
curr.Remove(next);
Debug.Assert(next.IsVisible);
}
}
}
The only real quirk I noticed while testing this is that moving a window from one desktop to another can move it to the bottom of the Z-order when you first switch the desktop, then move the window. No such problem if you do it the other way around.
There is this guy that made a application to map keyboard shorcut to move a window between virtual desktop.
https://github.com/Grabacr07/SylphyHorn
(I use it every day )
He has a blog where he explain what he did
http://grabacr.net/archives/5701 ( you can use google translate it is in japanese)
He in fact used the same api mantionned in the Alberto Tostado response.
http://www.cyberforum.ru/blogs/105416/blog3671.html
and the api can be found on his github https://github.com/Grabacr07/VirtualDesktop
The api is really simple to use BUT it seems impossible to move a window from another process.
public static bool MoveToDesktop(IntPtr hWnd, VirtualDesktop virtualDesktop)
{
ThrowIfNotSupported();
int processId;
NativeMethods.GetWindowThreadProcessId(hWnd, out processId);
if (Process.GetCurrentProcess().Id == processId) // THAT LINE
{
var guid = virtualDesktop.Id;
VirtualDesktop.ComManager.MoveWindowToDesktop(hWnd, ref guid);
return true;
}
return false;
}
To workaround this problem they made another implementation that they use alongside the one in the russian blog
if (VirtualDesktopHelper.MoveToDesktop(hWnd, right) //<- the one in the russian blog
|| this.helper.MoveWindowToDesktop(hWnd, right.Id)) <- the second implementation
The second implementation can be found here: https://github.com/tmyt/VDMHelper
This one can move a window from another process to another desktop. BUT it is buggy right now. For exemple when i try to move some window like google chrome it crash.
So this is the result of my research. I m rigth now trying to make a StickyWindow feature with these api.
I fear that all about "Virtual desktops" in Windows 10 is undocumented, but in a Russian page I've seen documented the interfaces. I don't speak Russian but seems that they have used reversed engineering. Anyway, the code is very clear (Thanks to them!).
Keep an eye here:
http://www.cyberforum.ru/blogs/105416/blog3671.html
I've been trying to see if the old API's CreateDesktop, OpenDesktop, etc... is linked to the new Virtual-Desktops, but no way...
The interfaces work with the final production release of Windows 10 (2015-05-08), but you shouldn't use them in a real wide distributed application until Microsoft documents them. Too much risk.
Regards.

boost locking mutex deadlocks

I have code that I am trying to guard using boost locking mechanism. The problem is that RecomputeStuff can not only be called from RemoveStuff, but it can also be called from another thread. My question is, using these boost locking mechanisms, what is the correct way to fix RecomputeStuff? The way it is now it deadlocks.
#include <boost/thread.hpp>
boost::shared_mutex values_mutex;
int globaldata;
class A
{
public:
void RecomputeStuff();
void RemoveStuff();
private:
std::vector<std::string> data;
};
//Note, RecomputeStuff just reads from std::vector<std::string> data, but it also writes to other global stuff that RemoveStuff also writes to.
void A::RecomputeStuff()
{
boost::upgrade_lock<boost::shared_mutex> lock(values_mutex);
boost::upgrade_to_unique_lock<boost::shared_mutex> unique_lock(lock);
// this function reads std::vector<std::string> data
// but also modifies `globaldata` that RemoveStuff also modifies.
}
void A::RemoveStuff()
{
boost::upgrade_lock<boost::shared_mutex> lock(values_mutex);
boost::upgrade_to_unique_lock<boost::shared_mutex> unique_lock(lock);
//here, remove stuff from std::vector<std::string> data
//...then call RecomputeStuff
RecomputeStuff();
// modify `globaldata`
}
A solution is to move the not locked code of the A::RecomputeStuff method to a separate one and call it from the A::RemoveStuff and A::RecomputeStuff. See the code below
boost::shared_mutex values_mutex;
int globaldata;
class A
{
private:
void RecomputeStuffUnsafe();
public:
void RecomputeStuff();
void RemoveStuff();
private:
std::vector<std::string> data;
};
void A::RecomputeStuffUnsafe()
{
// this function reads std::vector<std::string> data
// but also modifies `globaldata` that RemoveStuff also modifies.
}
//Note, RecomputeStuff just reads from std::vector<std::string> data, but it also writes to other global stuff that RemoveStuff also writes to.
void A::RecomputeStuff()
{
boost::upgrade_lock<boost::shared_mutex> lock(values_mutex);
boost::upgrade_to_unique_lock<boost::shared_mutex> unique_lock(lock);
RecomputeStuffUnsafe();
}
void A::RemoveStuff()
{
boost::upgrade_lock<boost::shared_mutex> lock(values_mutex);
boost::upgrade_to_unique_lock<boost::shared_mutex> unique_lock(lock);
//here, remove stuff from std::vector<std::string> data
//...then call RecomputeStuff
RecomputeStuffUnsafe();
// modify `globaldata`
}
Edit #00:
Also upgrade_lock has a constructor which accepts the try_to_lock_t tag. It looks like what you are asking for.

fail to get all parameters passed to function in log4net logger

I am creating a log file by using log4net, i logged the result in the .xml file, every thing is working perfect but i have one issue, i used library class and reference it in the form, in form on button click i called log function in logger file and pass four parameters i get all other records but fail to get the logging properties. i am using the fallowing code to write in the xml file.
public class MyXmlLayout : XmlLayoutBase
{
protected override void FormatXml(XmlWriter writer, LoggingEvent loggingEvent)
{ writer.WriteStartElement("LogEntry");
writer.WriteStartElement("Level");
writer.WriteString(loggingEvent.Level.DisplayName);
writer.WriteEndElement();
writer.WriteEndElement();
}
and these are the parameters i am passing to the function.
try
{
int i = 25;
int j = 0;
int foo = i / j;
}
catch (DivideByZeroException ex)
{
Logger.Log("ErrorLog", LoggingLevel.Error, "Attempted to divide by zero.",
new { User = "Fred Bloggs", Environment = "Production" }, ex);
}
can any one tell that how i can access "User" and "Environment"???
or any other suggestion.

Image not getting displayed/update in QLabel using SIGNAL-SLOT in ROS node

I am implementing the Qt code in ROS node. I have a header file in which i have defined all the members, Q_SIGNAL and Q_SLOTS. In my .cpp file i want to display an image when i press a button(assignButton). But when i press the button, nothing shows up.
To test whether the connect function is working properly or not, i tried to display an image in the imageLabel which is stored in my laptop..and it worked.
PROBLEM:- I am taking the images from simulator in ROS through the
void SelectionInterface::imageCallback(const sensor_msgs::ImageConstPtr& msg) and i want to display those images in imageLabel by SIGNAL-SLOT..but its not getting displayed..no error
My code is following:-
1. Header file-- SelectionInterface.h
class SelectionInterface : public QMainWindow
{
Q_OBJECT
public:
SelectionInterface(ros::NodeHandle *nh, RosThread *rt, QMainWindow *parent = 0);
~SelectionInterface();
private:
RosThread *rosThread;
ros::NodeHandle *nodeHandle;
// ROS Subscribers
image_transport::Subscriber image_sub;
void imageCallback(const sensor_msgs::ImageConstPtr& msg);
// More Memberfunctions and Variables
QWidget *newCentralWidget;
QPushButton *quitButton;
QPushButton *assignButton;
QVBoxLayout *layout;
QLabel *imageLabel;
QImage image;
// ...
protected:
void closeEvent(QCloseEvent *event);
Q_SIGNALS:
void windowClosedSignal();
private Q_SLOTS:
void quitInterface();
void assignImage();//QImage
};
2. .cpp file
#include "SelectionInterface.h"
#include <iostream>
SelectionInterface::SelectionInterface(ros::NodeHandle *nh, RosThread *rt, QMainWindow *parent): QMainWindow (parent)
{
rosThread = rt;
nodeHandle = nh;
// Subscribing and Publishing
image_transport::ImageTransport it(*nh);
// Setup user interface here
newCentralWidget = new QWidget;
quitButton = new QPushButton("Quit");
assignButton = new QPushButton("Assign Image");
layout = new QVBoxLayout;
imageLabel = new QLabel;
imageLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
layout->addWidget(imageLabel);
layout->addWidget(quitButton);
layout->addWidget(assignButton);
newCentralWidget->setLayout(layout);
this->setCentralWidget(newCentralWidget);
// Signal-Slot Connections
connect(this, SIGNAL(windowClosedSignal()), this, SLOT(quitInterface()));
connect(quitButton, SIGNAL(clicked()), this, SLOT(close()));
connect(assignButton, SIGNAL(clicked()), this, SLOT(assignImage()));
// ...
}
void SelectionInterface::imageCallback(const sensor_msgs::ImageConstPtr& msg)
{
QImage image(&(msg->data[0]), msg->width, msg->height, QImage::Format_RGB888);
}
SelectionInterface::~SelectionInterface()
{
//destructer (leave empty)
}
void SelectionInterface::closeEvent(QCloseEvent *event)
{
Q_EMIT windowClosedSignal();
}
void SelectionInterface::quitInterface()
{
rosThread->stop();
rosThread->wait();
std::cout << "Good bye.\n";
}
void SelectionInterface::assignImage()
{
imageLabel->setPixmap(QPixmap::fromImage(image));
}
I doubt QImage can replace ~ to your home path. Try to specify full path e.g. '/home/user/Pictures/wallpapers/buddha.jpg'.

Resources