我正在使用gcc编译器的平台上工作,但是boost无法在其上编译.
我想知道在gcc的std:tr1中包含shared_ptr的正确方法是什么?我查看的文件说不要直接包含它,我可以告诉其他任何文件都不包含它:|
我有一个QTableView,我想在编辑模式下显示最后一列.(这是一个QComboBox,用户应该能够始终更改值.)
我想我已经在Qt文档中看到了解决方案,但我再也找不到了.有一个简单的方法吗?
我想我可以通过使用openPersistentEditor()每个单元格来存档这种效果,但我正在寻找更好的方法.(比如只为整列指定一次.)
我想显示一个QListView,其中每个项目都是带有一些标签的复选框.复选框应始终可见.我能想到的一种方法是使用自定义委托和QAbstractListModel.有更简单的方法吗?你能提供最简单的代码片段吗?
提前致谢
对于可以在文本编辑器中完成的小型逻辑程序,为了跟踪我使用经典System.out.println().
我猜你们都知道在大量迭代的块中使用它是多么令人沮丧.为什么这么慢?它背后的原因是什么?
我有兴趣计算一个节点的物理位置,QTreeView但是找不到这样做的方法(除了自己计算它,考虑到鲁棒性,这很麻烦且容易出错QTreeView).
有没有一种标准方法可以找到与a相关的数据的绘制位置QModelIndex(类似于将indexAt()位置映射到a的方式QModelIndex)?
我正在使用Qt开发一个科学数据采集应用程序.由于我不是Qt的深度专家,我想从社区建议一些关于以下问题的建筑:
该应用程序支持多个硬件采集接口,但我想在这些接口之上提供通用API.每个接口都有一个样本数据类型和一个数据单位.所以我将每个设备的样本矢量表示std::vector为Boost.Units数量(即std::vector<boost::units::quantity<unit,sample_type> >).我想使用多播式架构,其中每个数据源将新接收的数据广播给一个或多个感兴趣的各方.Qt的信号/插槽机制非常适合这种风格.所以,我希望每个数据源发出一个信号
typedef std::vector<boost::units::quantity<unit,sample_type> > SampleVector
signals:
void samplesAcquired(SampleVector sampleVector);
Run Code Online (Sandbox Code Playgroud)
适用于该设备的unit和sample_type.由于QObject元对象编译器不支持tempalted 子类,因此似乎没有办法为定义samplesAcquiredSignal的所有数据源都有一个(tempalted)基类.换句话说,下面将不工作:
template<T,U> //sample type and units
class DataSource : public QObject {
Q_OBJECT
...
public:
typedef std::vector<boost::units::quantity<U,T> > SampleVector
signals:
void samplesAcquired(SampleVector sampleVector);
};
Run Code Online (Sandbox Code Playgroud)
我能够提出的最佳选择是双层方法:
template<T,U> //sample type and units
class IAcquiredSamples {
public:
typedef std::vector<boost::units::quantity<U,T> > SampleVector
virtual shared_ptr<SampleVector> acquiredData(TimeStamp ts, unsigned long nsamples);
};
class DataSource : public QObject {
...
signals:
void samplesAcquired(TimeStamp ts, unsigned …Run Code Online (Sandbox Code Playgroud) 我想检查给定的double/float变量是否具有实际的位模式0x0.不要问为什么,它在qIsNull()我想成为的Qt()函数中使用constexpr.
原始代码使用了一个联合:
union { double d; int64_t i; } u;
u.d = d;
return u.i == 0;
Run Code Online (Sandbox Code Playgroud)
这constexpr当然不起作用.
接下来的尝试是reinterpret_cast:
return *reinterpret_cast<int64_t*>(&d) == 0;
Run Code Online (Sandbox Code Playgroud)
但是虽然它constexpr在GCC 4.7 中起作用,但它在Clang 3.1中失败(正确地,指针操作的b/c).
最后的想法是去Alexandrescuesque并做到这一点:
template <typename T1, typename T2>
union Converter {
T1 t1;
T2 t2;
explicit constexpr Converter( T1 t1 ) : t1(t1) {}
constexpr operator T2() const { return t2; }
};
// in qIsNull():
return Converter<double,int64_t>(d);
Run Code Online (Sandbox Code Playgroud)
但对于Clang来说,这也不够聪明:
note: read of member 't2' of …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用标准QCheckbox/QRadioButton与Qt建立多行复选框/单选按钮.
我找不到直接解决方案,因为QRadioButton{wrap:true;}没有效果.唯一可能的是访问QRadioButton->label->setLineWrap(true)但是
除了将QRadioButton和QLabel放在一起之外,还有什么想法?
Thx,鲍里斯.
我正在尝试重置UIPickerView点击按钮.我的pickerview id是在运行时创建的,我已经设置了委托.谷歌搜索后,我找到了
[pickerView reloadAllComponents];
Run Code Online (Sandbox Code Playgroud)
但这会让我的应用程序每次到达时都会崩溃.
索引0处的对象是"从列表中选择",然后是项目.单击提交按钮时,我希望"从列表中选择"应保留在我的标签顶部(选定索引:0).
这是我的代码
ViewDidload
pickerView = [[UIPickerView alloc] init];
pickerView.delegate = self;
pickerView.dataSource = self;
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
return 1;
}
// Total rows in our component.
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
return [nameArray count];
}
// Display each row's data.
-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
return [nameArray objectAtIndex: row];
}
// Do something with the selected row.
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
dlbl.hidden=YES;
NSLog(@"You selected this: %@", [nameArray objectAtIndex: row]);
[btnSelectDesigner setTitle:[nameArray objectAtIndex: row] forState:UIControlStateNormal];
}
Run Code Online (Sandbox Code Playgroud)
并在按钮上单击: …
虽然比较组件,用于std::shared_ptr对boost::shared_ptr,我注意到,GCC生成一大堆更多的代码
void test_copy(const std::shared_ptr<int> &sp) { auto copy = sp; }
Run Code Online (Sandbox Code Playgroud)
( https://godbolt.org/z/efTW6MoEh – 超过 70 行汇编程序) 而不是 boost 版本,GCC 的 shared_ptr 实现基于该版本:
void test_copy(const boost::shared_ptr<int> &sp) { auto copy = sp; }
Run Code Online (Sandbox Code Playgroud)
(https://godbolt.org/z/3aoGq1f9P – 大约 30 行汇编程序)。
特别是,我对std::shared_ptr版本中的以下说明感到困惑,我在来源中(很容易)找不到提到的说明。
movq __gthrw___pthread_key_create(unsigned int*, void (*)(void*))@GOTPCREL(%rip), %rbx
Run Code Online (Sandbox Code Playgroud)
有人能解释一下为什么std::shared_ptr生成比 多得多的代码boost::shared_ptr吗?我错过了一些神奇的命令行选项吗?
c++ ×5
qt ×3
qt4 ×2
shared-ptr ×2
assembly ×1
boost ×1
c++11 ×1
casting ×1
checkbox ×1
console ×1
constexpr ×1
gcc ×1
gnu ×1
ipad ×1
iphone ×1
java ×1
performance ×1
pyqt ×1
python ×1
qcheckbox ×1
qlistview ×1
qmodelindex ×1
qtableview ×1
qtreeview ×1
radio-button ×1
stdout ×1
templates ×1
tr1 ×1
uipickerview ×1
x86-64 ×1