wxListView in MOTIF doesn't refresh after scrolling - wxwidgets

I'm working with wxWidgets 2.8 on a MOTIF (sic) linux box.
I noticed that wxListView and wxListCtrl don't refresh correctly their content after a scroll. When I act on the scrollbar, the new items are invisible until I click on them.
The misbehaviour is present also in the sample "listctrl" that comes with the wxWidgets library.
How can I solve this problem?

It seems it's a wxWidgets bug.
My first try was to work-around it by refreshing the wxListView after a scroll. Unfortunately, it seems wxWidgets doesn't provide scroll events for wxListView/wxListCtrl.
Finally, I solved my problem using the following ListView instead of wxListView in my code:
// listview.h
#ifndef LISTVIEW_H_
#define LISTVIEW_H_
#include <wx/listctrl.h>
class RefreshingListView : public wxListView, private wxTimer
{
public:
RefreshingListView( wxWindow *parent, wxWindowID id,
const wxPoint &pos=wxDefaultPosition,
const wxSize &size=wxDefaultSize,
long style=wxLC_ICON,
const wxValidator &validator=wxDefaultValidator,
const wxString &name=wxListCtrlNameStr ) :
wxListView( parent, id, pos, size, style, validator, name ),
lastTopItem( GetTopItem() )
{
Start( 300 ); // ms
}
// override
virtual void Notify() { CheckTopItem(); }
private:
void CheckTopItem()
{
long it = GetTopItem();
if ( it != lastTopItem )
{
Refresh();
lastTopItem = it;
}
}
long lastTopItem;
};
#ifdef __WXMOTIF__
typedef RefreshingListView ListView;
#else
typedef wxListView ListView;
#endif
#endif // LISTVIEW_H_
Maybe it can be useful to someone :-)

Related

wxWidgets issue using wxClientDc

i'm be beginning to use wxWidgets in a project and i'm using wxClientDc to draw on a image. I created a class that inherits wxStaticBitmap adding my properties and drawing over it. To clear the image i'm setting the background as the same wxBitmap that i used in MY image:
//that is my class
class myImage : public wxStaticBitmap {
public:
wxBitmap frame; //imagem
myImage(wxWindow* parent, wxWindowID id, wxPoint pos, wxSize size, wxBitmap frame);
private:
void redesenha();
void mouseUp(wxMouseEvent& event);
void mouseDown(wxMouseEvent& event);
void mouseMove(wxMouseEvent& event);
wxDECLARE_EVENT_TABLE();
};
myImage::myImage(wxWindow* parent, wxWindowID id, wxPoint pos, wxSize size, wxBitmap frame): wxStaticBitmap(parent, id, frame, pos, size){
this->frame = frame;
}
//that is my function to clear my image
void myFrame::onClickClear(wxCommandEvent& event)
{
wxClientDC dc(myImg);
dc.SetBackground(wxBrush(myImg->frame)); //frame is a wxBitmap type
dc.Clear();
}
The issue is that works in my laptop but when my friend download and compile it's doesn't work in his laptop.
If you need to "clear" a wxStaticBitmap, just assign a solid bitmap with the given colour.
More generally speaking, you shouldn't try to draw over the native controls (such as wxStaticBitmap) and you shouldn't use wxClientDC at all as drawing is only supported from wxEVT_PAINT handlers on many modern systems (e.g. macOS).

QTcpSocket does not emit connected()

I'm using QT5 and starting out with a basic Server/Client setup. I'm looking at going single threaded for both apps as there is no heavy processing on network data. Now, from everything I've read and researched here, when using asynchronous approach, you don't use waitForXXXX() otherwise it messes up all the signals and slots. The problem - On the client end, the connected() signal is either never emitted or never processed, even though the server consoles tells me that a new client has connected. I've been working on the same issue for 2 weeks now and couldn't find the exact same issue anywhere. I've stripped back both apps to the minimum and still no luck - also stripped out the UI part now - I just want see the console working. I have also tried switching to public slots and changing the signal/slot connection type and still have the same problem.
If you require code from the server, please let me know, but here is the basics of the client:
main.cpp
#include "QGameSocket.h"
#include <QtWidgets/QApplication>
#include <windows.h>
int main(int argc, char *argv[])
{
AllocConsole();
freopen( "conin$", "r", stdin );
freopen( "conout$", "w", stdout );
freopen( "conout$", "w", stderr );
QApplication a( argc, argv );
QGameSocket* pSocket = new QGameSocket();
return a.exec();
}
QGameSocket.h
#ifndef _QGAMESOCKET_H
#define _QGAMESOCKET_H
#include <QtNetwork/qtcpsocket.h>
#pragma comment ( lib, "Qt5Network.lib" )
class QGameSocket: public QObject
{
Q_OBJECT
public:
explicit QGameSocket( QObject* pParent = 0 );
~QGameSocket();
private slots:
void __OnConnected();
void __OnReadyRead();
private:
QTcpSocket* m_pSocket;
};
#endif
QGameSocket.cpp
#include "QGameSocket.h"
#include <qdatastream.h>
QGameSocket::QGameSocket( QObject* pParent ) :
QObject( pParent )
{
m_pSocket = new QTcpSocket();
connect( m_pSocket, SIGNAL( connected() ), this, SLOT( __OnConnected() ) );
connect( m_pSocket, SIGNAL( readyRead() ), this, SLOT( __OnReadyRead() ) );
const QString strHost = "127.0.0.1";
qDebug() << "Connecting to host ...";
m_pSocket->connectToHost( strHost, 27015 );
}
QGameSocket::~QGameSocket()
{
m_pSocket->deleteLater();
}
void QGameSocket::__OnConnected()
{
qDebug() << "Successfully connected to host!";
}
void QGameSocket::__OnReadyRead()
{
//handle messages
}
Any help would be much appreciated, thank you!
I finally figured it out - I was using the release network library, not the debug library.
I changed:
#pragma comment ( lib, "Qt5Network.lib" )
to
#pragma comment ( lib, "Qt5Networkd.lib" )

Automatic warning on fixed point overflow in SystemC

Is there a way i can enable an automatic warning for my SystemC simulation whenever a fixed point variable overflows?
I already discovered the overflow_flag() function, but that one have to be check manually for every time i write to a signal in my code. Also, as I interpret the documentation, this flag does not discern between overflowing and precision loss?
Is there a way i can enable an automatic warning for my SystemC simulation whenever a fixed point variable overflows?
Not in a centralized, standard way.
If you want to monitor a fixed set of variables, you may be able to use the sc_fxnum_observer extension available in some SystemC implementations.
To use it, you have to #define SC_ENABLE_OBSERVERS before including SystemC (ideally from your compiler command-line). The allows you to "attach" an observer to your sc_fixed<...> (and related) classes, which is notified upon the following events:
class sc_fxnum_observer
{
public:
virtual void construct( const sc_fxnum& );
virtual void destruct( const sc_fxnum& );
virtual void read( const sc_fxnum& );
virtual void write( const sc_fxnum& );
};
You can then for example check the overflow_flag in a custom observer's write function:
struct overflow_observer : sc_dt::sc_fxnum_observer
{
virtual void write( const sc_fxnum& v )
{
if( v.overflow_flag() )
// ...
}
};
During construction of a variable, you can pass a pointer to the observer then:
overflow_observer my_overflow_observer;
sc_dt::sc_fixed<...> f( &my_overflow_observer );
For a signal, the easiest solution is to derive a specialized signal and check for the overflow flag inside an overridden update function.
template <int W, int I,
sc_q_mode Q = SC_DEFAULT_Q_MODE_,
sc_o_mode O = SC_DEFAULT_O_MODE_, int N = SC_DEFAULT_N_BITS_>
class fixed_signal : public sc_core::sc_signal< sc_dt::sc_fixed<W,I,Q,O,N> >
{
typedef sc_core::sc_signal< sc_dt::sc_fixed<W,I,Q,O,N> > base_type;
public:
// constructor, etc.
// ...
using base_type::operator=;
protected:
void update()
{
base_type::update();
if( read().overflow_flag() )
// ...
}
};
Also, as I interpret the documentation, this flag does not discern between overflowing and precision loss?
Yes.

How do I pass QMainWindow resize events down to a QGLWidget contained in the QMainWindow?

Initially, I followed the structure of http://qt-project.org/wiki/How_to_use_OpenGL_Core_Profile_with_Qt. I created a vanilla Visual Studio 2010 Qt application project, clicked on the .ui file to start Qt Designer, inserted a QWidget and promoted it to myglwidget. I then created a myglwidget subclass of QGLWidget.
That worked fine, and I got my red triangle.
The issue is that myglwidget doesn't get any of the resize events when the main window is resized, even if I set the widget size properties to "expanding."
And when I restructure my app constructor to call setCentralWidget(&myglwidget_) the code compiles and runs but no OpenGL window appears.
I'm not seeing how to resize my widget to match the main window size. I'm also not understanding why the setCentralWidget approach didn't work.
I believe I know how to solve the problem by writing explicit Qt code, but that defeats the purpose of my trying to build an OpenGL app in Qt using Qt Designer.
The following code for the application "baz6" fixes the problem. The code I inserted in the wizard-generated code is flagged with //***
baz6.h:
#ifndef BAZ6_H
#define BAZ6_H
#include <QtGui/QMainWindow>
#include "ui_baz6.h"
#include "myglwidget.h" //***
#include <QResizeEvent>
class baz6 : public QMainWindow
{
Q_OBJECT
public:
baz6(QWidget *parent = 0, Qt::WFlags flags = 0);
~baz6();
private:
Ui::baz6Class ui;
myGLWidget *myglwidget_; //***
};
#endif // BAZ6_H
baz6.c:
#include "baz6.h"
#include "myglwidget.h"
baz6::baz6(QWidget *parent, Qt::WFlags flags)
: QMainWindow(parent, flags)
{
ui.setupUi(this);
myglwidget_ = new myGLWidget(); //***
setCentralWidget(myglwidget_); //***
}
baz6::~baz6()
{
}
Previously, I had not explicitly constructed the myGLWidget.

How do I use WTL in a DLL?

I'm trying to use WTL within an in-process COM server DLL (an IE BHO), but am struggling with _Module.
My DLL needs CMyModule derived from CAtlDllModuleT<>:
class CMyModule : public CAtlDllModuleT< CMyModule >
{
public:
DECLARE_LIBID(LIBID_MyLib)
DECLARE_REGISTRY_APPID_RESOURCEID(IDR_MYPROJ, "{...}")
};
CMyModule _Module;
extern "C" BOOL WINAPI DllMain(...)
{
hInstance;
return _Module.DllMain(dwReason, lpReserved);
}
...
STDAPI DllUnregisterServer(void)
{
return _Module.DllUnregisterServer();
}
But this conflicts with most WTL examples, which require something like this within stdafx.h:
extern CAppModule _Module; // WTL version of CComModule
No matter which way I do it, I (unsurprisingly) get compile errors. CMyModule derived from CAppModule borks on _Module.DllUnregisterServer(), etc. CMyModule derived from CAtlDllModuleT<> borks on code like _Module.GetMessageLoop().
Any good references on how WTL is supposed to work within a DLL? Google finds lots of questions, with few answers.
I have a project that uses WTL in a DLL. I looked at how my headers are set up and it looks like I hacked around this same problem...
I have my module set up like your sample code inheriting from CAtlDllModuleT<> except the name of the global module variable is _AtlModule rather than _Module. For example:
class CMyModule : public CAtlDllModuleT< CMyModule >
{
public:
DECLARE_LIBID(LIBID_MyLib)
DECLARE_REGISTRY_APPID_RESOURCEID(IDR_MYPROJ, "{...}")
};
CMyModule _AtlModule;
So, all of the DllMain.cpp entry points use _AtlModule. Then in the stdafx.h file it looks like this:
// WTL includes
#define _Module (*_pModule)
#include <atlapp.h>
#include <atlctrls.h>
#include <atldlgs.h>
#undef _Module
That _pModule thing is defined in atlbase.h like:
__declspec(selectany) CComModule* _pModule = NULL;
There must be a better way, but this does work.
Have you considered the option of multiple inheritance? Try inheriting from both CAtlDllModule and CAppModule since you need both.
I use WTL in an Office add-in; the following works for me. (At the bottom of stdafx.h)
class DECLSPEC_UUID("XXXX-...") MyLib;
using namespace ATL;
/*
* Application module
*/
class CAddInModule : public CAtlDllModuleT< CAddInModule >
{
public:
CAddInModule() : m_hInstance(NULL)
{
}
DECLARE_LIBID(__uuidof(MyLib))
HINSTANCE GetResourceInstance()
{
return m_hInstance;
}
void SetResourceInstance(HINSTANCE hInstance)
{
m_hInstance = hInstance;
}
private:
HINSTANCE m_hInstance;
};
extern CAddInModule _AtlModule;
And then the DLL main use _AtlModule:
// DLL Entry Point
extern "C" BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
{
_AtlModule.SetResourceInstance(hInstance);
return _AtlModule.DllMain(dwReason, lpReserved);
}
// Used to determine whether the DLL can be unloaded by OLE
STDAPI DllCanUnloadNow(void)
{
return _AtlModule.DllCanUnloadNow();
}
// Returns a class factory to create an object of the requested type
STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
{
return _AtlModule.DllGetClassObject(rclsid, riid, ppv);
}
// DllRegisterServer - Adds entries to the system registry
STDAPI DllRegisterServer(void)
{
// registers object, typelib and all interfaces in typelib
HRESULT hr = _AtlModule.DllRegisterServer();
return hr;
}
// DllUnregisterServer - Removes entries from the system registry
STDAPI DllUnregisterServer(void)
{
HRESULT hr = _AtlModule.DllUnregisterServer();
return hr;
}